Xml 如何使用ed line editor删除两个搜索匹配之间的行
我有一个正在编辑的文本文件(在我的例子中是JMeter XML),我使用ed查找两行,它们标记XML部分的第一行和最后一行 如何删除两个搜索匹配之间的行 示例文件:Xml 如何使用ed line editor删除两个搜索匹配之间的行,xml,text,ed,Xml,Text,Ed,我有一个正在编辑的文本文件(在我的例子中是JMeter XML),我使用ed查找两行,它们标记XML部分的第一行和最后一行 如何删除两个搜索匹配之间的行 示例文件: 1 <hashTree> 2 <ConstantTimer guiclass="ConstantTimerGui" testclass="ConstantTimer" testname="Constant Timer" enabled="true"> 3 <stringProp name="Consta
1 <hashTree>
2 <ConstantTimer guiclass="ConstantTimerGui" testclass="ConstantTimer" testname="Constant Timer" enabled="true">
3 <stringProp name="ConstantTimer.delay">300</stringProp>
4 </ConstantTimer>
6 </hashTree>
1
2.
3 300
4.
6.
我想删除包含的第2-4行。您可以标记找到的行,并使用以下代码在两个标记之间执行删除操作
1 <---- Jump to line 1
/ConstantTimer <---- Search for the first 'ConstantTimer'
kx <---- Mark it as 'x'
/ConstantTimer <---- Search for the second 'ConstantTimer'
ky <---- Mark it as 'y'
'x,'yd <---- delete between the two marks 'x and 'y
w <---- save the changes
q <---- quit ed
1您可以标记找到的行,并使用以下代码在两个标记之间执行删除操作
1 <---- Jump to line 1
/ConstantTimer <---- Search for the first 'ConstantTimer'
kx <---- Mark it as 'x'
/ConstantTimer <---- Search for the second 'ConstantTimer'
ky <---- Mark it as 'y'
'x,'yd <---- delete between the two marks 'x and 'y
w <---- save the changes
q <---- quit ed
1如果要执行所有操作,可以使用g
命令查找开始,然后使用+
从下一行开始,然后向前搜索结束标记,使用-
向后移动,然后删除结果内容:
g/<hashTree>/+,/<\/hashTree>/-d
g//+,//-d
注意,这假设每个
块都有一些要删除的内容。如果有任何空块,它可能会删除比您想要的更多的内容。如果您想全部删除,可以使用g
命令找到开始,然后使用+
从下一行开始,然后向前搜索结束标记,然后使用-
向后移动,然后删除生成的内容:
g/<hashTree>/+,/<\/hashTree>/-d
g//+,//-d
注意,这假设每个
块都有一些要删除的内容。如果有任何空块,它可能会删除比您想要的更多的内容