|
蓝森林 http://www.lslnet.com 2006年6月26日 11:18
[求助]如何在指定行前面增加几行?
我想在一个文本中指定的某行前面增加几行,该如何实现,利用sed或者awk,或者其他的吧,谢谢大家指点!! |
[求助]如何在指定行前面增加几行?
来个笨办法 :oops: :oops: :oops:只能在已知字符下加
原文件如下:
[code]# cat grade.txt
M.Tans 5/99 48311 Green 8 40 44
J.Lulu 06/99 48317 green 9 24 26
P.Bunny 02/99 48 Yellow 12 35 28
J.Troll 07/99 4842 Brown-3 12 26 26
L.Tansl 05/99 4712 Brown-2 12 30 28[/code]
现在在最后一行前加上两行空行:
[code] # awk '{gsub(/L.Tansl/,"\n\nL.Tansl")}{print $0}' grade.txt
M.Tans 5/99 48311 Green 8 40 44
J.Lulu 06/99 48317 green 9 24 26
P.Bunny 02/99 48 Yellow 12 35 28
J.Troll 07/99 4842 Brown-3 12 26 26
L.Tansl 05/99 4712 Brown-2 12 30 28[/code] |
[求助]如何在指定行前面增加几行?
#!/bin/sed -f
4 i\
insert this line before line 4.
或者,
#!/bin/sed -f
/specified-word/ i\
insert this line before line contained specified-word. |
[求助]如何在指定行前面增加几行?
-->
呵,sed这么方便啊,俺还没看呢 :oops: :oops: :oops: |
[求助]如何在指定行前面增加几行?
多谢 wingger和chenl!! |
[求助]如何在指定行前面增加几行?
用ed更简单
[code]
ed file<<!
4i
some string
.
w
!
[/code] |
| |