如何用 sed 实现 `cat -n' 的功能?

如何用 sed 实现 `cat -n' 的功能?

也就是把文件的每一行加上行号:
引用:
-(dearvoid@LinuxEden:Forum)-(~/tmp)-
[$$=3958 $?=0] ; cat file
There are no miracles, and using a language facility or a
technique that you only partially understand in production
code is dangerous.

- Bjarne Stroustrup
-(dearvoid@LinuxEden:Forum)-(~/tmp)-
[$$=3958 $?=0] ; cat -n file
     1  There are no miracles, and using a language facility or a
     2  technique that you only partially understand in production
     3  code is dangerous.
     4
     5  - Bjarne Stroustrup
-(dearvoid@LinuxEden:Forum)-(~/tmp)-
[$$=3958 $?=0] ; bye
      
:%!sed '='
:%!sed '/^[0-9]/ {N;s/\n/\t/;}'

这是我常用的方法.      
受 TUDOU01 的启发:
引用:
-(dearvoid@LinuxEden:Forum)-(~/void/sed)-
[$$=5121 $?=0] ; cat nl-sed.sh
#!/bin/bash

sed -n -e '=;p' | sed -e '
:start
/^[0-9]\{6,\}/bnext

s/^/     /
s/.*\(.\{6\}\)$/\1/

:next
N
s/\n/  /

n
bstart'
-(dearvoid@LinuxEden:Forum)-(~/void/sed)-
[$$=5121 $?=0] ; ./nl-sed.sh < nl-sed.sh
     1  #!/bin/bash
     2
     3  sed -n -e '=;p' | sed -e '
     4  :start
     5  /^[0-9]\{6,\}/bnext
     6
     7  s/^/     /
     8  s/.*\(.\{6\}\)$/\1/
     9
    10  :next
    11  N
    12  s/\n/  /
    13
    14  n
    15  bstart'
-(dearvoid@LinuxEden:Forum)-(~/void/sed)-
[$$=5121 $?=0] ; bye
      
不会sed
nl -ba更简单