- 论坛徽章:
- 3
|
cjaizss 发表于 2012-03-07 14:41
=不是放在模式空间里的,不可编辑
以下才是把行号放到模式空间里去的
info sed里面的比我写的这个稍短
- #!/usr/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
复制代码 |
|