I was hoping someone here would help me understand the issue. Moreover, I was hoping I could get a better, more elegant sed solution. While perl or awk might be more appropriate, I am actually looking for 100% sed approach.
Thanks in advance
sed -e '1{
x
s/.*/0/
x
}
/^>/{
x
:d
s/9\(_*\)$/_\1/
td
s/^\(_*\)$/0\1/
s/8\(_*\)$/9\1/
s/7\(_*\)$/8\1/
s/6\(_*\)$/7\1/
s/5\(_*\)$/6\1/
s/4\(_*\)$/5\1/
s/3\(_*\)$/4\1/
s/2\(_*\)$/3\1/
s/1\(_*\)$/2\1/
s/0\(_*\)$/1\1/
s/_/0/g
x
G
s/.*\n/>seq /
}' file
Increment code take in gnu sed documentation ( info sed )
Ha! This is perhaps the first time i find something to nit-pick in anything the infallible Don has pontificated. Actually it is posssible to do arithmetic in sed . Here, for example, is addition/subtraction (from stackoverflow):
s/[0-9]/<&/g
s/0//g
s/1/|/g
s/2/||/g
s/3/|||/g
s/4/||||/g
s/5/|||||/g
s/6/||||||/g
s/7/|||||||/g
s/8/||||||||/g
s/9/|||||||||/g
: tens
s/|</<||||||||||/g
t tens
s/<//g
s/+//g
: minus
s/|-|/-/g
t minus
s/-$//
: back
s/||||||||||/</g
s/<\([0-9]*\)$/<0\1/
s/|||||||||/9/
s/||||||||/8/
s/|||||||/7/
s/||||||/6/
s/|||||/5/
s/||||/4/
s/|||/3/
s/||/2/
s/|/1/
s/</|/g
t back
In fact, sed is a (Turing-) complete programming language. This can be shown by either writing a Turing-machine in sed (shown here) or by writing an interpreter for another Turing-complete language. With much fanfare, here is a Brainfuck-interpreter written in sed.
[/not-quite-serious-mode]
I hope this helps (well, actually i doubt it, but this is a holiday where i am, so it is a day off and it is fun).
bakunin
PS: Input to the sed-script above would be "100+15" or "250-173"