Regex 如何使用sed查找多行图案并添加新行

Regex 如何使用sed查找多行图案并添加新行,regex,awk,sed,Regex,Awk,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 试试这个sed命令。我希望这能帮助你 sed ':loop ; N ; /\n$

我不熟悉使用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

试试这个
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

此命令将为您执行此操作

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

o@o:~$ 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