-i 可以直接在源xml文件中删除
另外为了避免可能的异常情况,最好先
echo "" >> test.xml
test.xml命令执行之前内容为:
<root>
<user>
<name type="string">yaowei</name>
<age type="int">-1</age>
<character type="string">xxx</character>
</user>
</root>
执行语句
sed -i '/<age type="int">.*<\/age>/d' test.xml
注意
.*为正则
d为删除
后,内容为:
<? xml version="1.0" encoding="utf-8">
<root>
<user>
<name type="string">yaowei</name>
<character type="string">xxx</character>
</user>
</root>