Last active
March 2, 2025 20:59
-
-
Save emanuele6/d846879d025fbbac674b676df6682b70 to your computer and use it in GitHub Desktop.
POSIX ed script that prepends line numbers to the lines of a file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1s/^/1 / | |
2,$g/^/-t -\ | |
s/ .*//\ | |
s/^9*$/0&/\ | |
t .\ | |
s/^.*[^9]\(9*\)$/\1 /\ | |
s/9/0/g\ | |
-s/9*$//\ | |
s/8$/9/\ | |
s/7$/8/\ | |
s/6$/7/\ | |
s/5$/6/\ | |
s/4$/5/\ | |
s/3$/4/\ | |
s/2$/3/\ | |
s/1$/2/\ | |
s/0$/1/\ | |
.,+2j | |
w | |
q |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot, this is genius. I love it.
Thank you for the script and for the explanation.
i couldn't understand it specifically because of the 9 replaced by 0 part and copying another line and the effect it had in the incrementation process.