Next: , Previous: cat -n, Up: Examples


4.8 空白行以外に番号を付ける

cat -bのエミュレートは,ほとんどcat -nと同じです — 我々 は,番号を付ける行と付けない行を選択する必要があっただけです.

このスクリプトの前回ものとの共通部分には,適切なsedスクリプト へのコメントがいかに重要かを表示するコメントを付けていません...

     #!/usr/bin/sed -nf
     
     /^$/ {
       p
       b
     }
     
     # Same as cat -n from now
     x
     /^$/ s/^.*$/1/
     G
     h
     s/^/      /
     s/^ *\(......\)\n/\1  /p
     x
     s/\n.*$//
     /^9*$/ s/^/0/
     s/.9*$/x&/
     h
     s/^.*x//
     y/0123456789/1234567890/
     x
     s/x.*$//
     G
     s/\n//
     h