2015-09-25 29 views
-1

我是使用'sed'的新手。我有一个文件,其中有一些文字如下。如何找到多行模式并使用sed添加新行

this is a test1 
length 12 
width 12 

this is test2 
length 50 
width 50 

我不知道多行sed命令是怎么样的。我想我的输出为

this is a test1 
length 12 
//width 12 
new width 40 

this is test2 
length 50 
width 50 

回答

0

试试这个sed命令。我希望这会帮助你,

sed ':loop ; N ; /\n$/{s/.*/\/\/&new width 40\n/} ; t loop' FileName.txt 

输出:

this is a test1 
length 12 
//width 12 
new width 40 

this is test2 
length 50 
width 50 
0

这个命令会为你做这个。

sed 's:\(width 12\)://\1\nnew width 40:g' 

[email protected]:~$ sed 's:\(width 12\)://\1\nnew width 40:g' se.file 
this is a test1 
length 12 
//width 12 
new width 40 

this is test2 
length 50 
width 50