#!/usr/bin/sed -nf # Carlos J.Duarte # copy all lines of input, prefixing only non blank lines by its number, # kind of `cat -b' # init counter 1{ x s/^/0/ x } # for blanks, don't incr count, but print /./!{ p b } # for the rest is the same as a `cat -n' 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 s/^/ / s/^.*\(......\)/\1/ G s/\n/ /p s/^ *// s/ .*// h