sed: cat -b
1
1 7.11 Numbering Non-blank Lines
1 ==============================
1
1 Emulating 'cat -b' is almost the same as 'cat -n'--we only have to
1 select which lines are to be numbered and which are not.
1
1 The part that is common to this script and the previous one is not
1 commented to show how important it is to comment 'sed' scripts
1 properly...
1
1 #!/usr/bin/sed -nf
1
1 /^$/ {
1 p
1 b
1 }
1
1 # Same as cat -n from now
1 x
1 /^$/ s/^.*$/1/
1 G
1 h
1 s/^/ /
1 s/^ *\(......\)\n/\1 /p
1 x
1 s/\n.*$//
1 /^9*$/ s/^/0/
1 s/.9*$/x&/
1 h
1 s/^.*x//
1 y/0123456789/1234567890/
1 x
1 s/x.*$//
1 G
1 s/\n//
1 h
1