Skip to content

Instantly share code, notes, and snippets.

@jrunning
Created June 19, 2017 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrunning/2e6667175354a8ba7322918a384ec372 to your computer and use it in GitHub Desktop.
Save jrunning/2e6667175354a8ba7322918a384ec372 to your computer and use it in GitHub Desktop.
decimal↔unary in GNU sed
#!/usr/bin/env sed -rf
# 2017 Jordan Running <jordan@jordanrunning.com>
s/^0$//
tZ
s/$/!:9876543210/
:
s/0!/!9/
t
s/(.)!(.*):(.*\1)(.)/\4\2:\3\4/
s/(.*):/;\1!:/
s/;0/;/
/;!/!b
s/!.*//
:Z
#!/usr/bin/env sed -rf
# 2017 Jordan Running <jordan@jordanrunning.com>
s/$/0!:0123456789/
:
/;/!bZ
s/9!/!0/
t
s/;!/;1/
s/(.)!(.*):(.*\1)(.)/\4\2:\3\4/
s/;(.*):/\1!:/
b
:Z
s/!.*//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment