Created
June 12, 2017 20:48
-
-
Save jrunning/91a7584d95fe10ef6b036d1c82bd385c to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
sed --version | head -1 | |
printf "%s\n%s" "$1" "$2" | gsed -r ' | |
x;N | |
G | |
s/\n/!@/ | |
: | |
/@\n/bZ | |
s/-!(.*)@ /\1 !@/ | |
s/!(.*[- ])(@.*1)$/\1!\2/ | |
s/@(.)(.*)1$/\1@\2/ | |
s/-!(.*-)(@.*)\n$/\1!\2\n1/ | |
s/(\n!@) /\1/ | |
s/-!(.* )(@.*)\n$/\1!\2\n1/ | |
s/-!(.*-)(@.*1)$/\1!\21/ | |
s/!(.*)-@([^ ]) /\1\2!@ / | |
t | |
s/ !@(.*)\n$/\n!@\1#/ | |
s/!(.*-)@(.*)\n$/\1\n!@\2#/ | |
s/!(.*)(@ | @)(.*)\n$/\1\n!@\3#/ | |
s/-!(.*[^-])@([^ ]) (.*)\n$/\1\2\n!@\3#/ | |
s/!(.+)@([^ ].*)\n$/\n!@\1\2#/ | |
/#|!@.*\n$/{s/#|\n$//;G;b} | |
:Z | |
s/-?!|@.*//g | |
s/ \n/\n/g | |
s/^/%/ | |
:B | |
G | |
/%.*\n.+\n/!bQ | |
:C | |
s/%([^\n])(.*)1$/\1%\2/ | |
tC | |
s/([^\n]+)%\n/%\1\n/ | |
:D | |
s/%([^ \n]* )(.*)1$/\1 %\2/ | |
tD | |
s/(^|\n)([^\n]+)%(.*1)$/\1%\2\3/ | |
tD | |
s/%([^\n]*)\n(.*)\n$/\1\n%\2/ | |
tB | |
:Q | |
s/%(.*)\n1*$/\1/' |
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
$ ./just.sh 111111 'Hello, world!' | |
sed (GNU sed) 4.2.2 | |
Hello, | |
world |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment