Linux伊甸园论坛 » Shell编程 » 如何用 sed 实现 `cat -n' 的功能?
clark
版主
-(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
查看个人网站
查看详细资料
TOP
认证会员
注册用户
-(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
超级版主