分页: 1 / 1

sed脚本的一点疑问

发表于 : 2011-04-19 20:36
cnLiuyix
如下的脚本

代码: 全选

#!/bin/sed -nf

     # Prime the pump on the first line
     x
     /^$/ s/^.*$/1/
	

     # Add the correct line number before the pattern
     G
     h

     # Format it and print it
     s/^/      /
     s/^ *\(......\)\n/\1  /p

     # Get the line number from hold space; add a zero
     # if we're going to add a digit on the next line
     g
     s/\n.*$//
     /^9*$/ s/^/0/

     # separate changing/unchanged digits with an x
     s/.9*$/x&/

     # keep changing digits in hold space
     h
     s/^.*x//
     y/0123456789/1234567890/
     x

     # keep unchanged digits in pattern space
     s/x.*$//
     # compose the new number, remove the newline implicitly added by G
     G
     s/\n//
     h
初学sed,这一行没看懂
/^$/ s/^.*$/1/
,哪位大侠能指点下~~多谢

Re: sed脚本的一点疑问

发表于 : 2011-04-20 13:09
Lys5300
显示所有内容,并把所有空白行置换为1. :em01