#!/usr/bin/sed -nf # Carlos J.Duarte # copy all lines of input, prefixed by its number, kind # of `cat -n' # switch to buffer x # init the counting 1{ s/^/0/ } # increment the count: first line == number 1 :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 # format the number like printf's `"%6d"' s/^/ / s/^.*\(......\)/\1/ # append the line to the number, and write: " " # note: this is the format of gnu-cat G s/\n/ /p # after printing the line, transform the line into the number, and # store it on buffer again s/^ *// s/ .*// h