【发布时间】:2019-06-21 06:02:24
【问题描述】:
我有一个 xml 文件,我想找到第二次出现的字符串,然后从字符串中删除第 2 行。以下是它的外观示例:
<application>
<app>
<Name>Tester</Name>
<Class>tester.update</Class>
<const>
<argument>READ_ONLY</argument>
</const>
<role>sysad</role>
</application>
<application>
<app>
<Name>Tester</Name>
<Class>tester.update</Class>
<const>
<argument>READ_ONLY</argument>
</const>
<role>tester</role>
</application>
这是我想要的样子:
<application>
<app>
<Name>Tester</Name>
<Class>tester.update</Class>
<const>
<argument>READ_ONLY</argument>
</const>
<role>sysad</role>
</application>
.
.
.
<application>
<app>
<Name>Tester</Name>
<Class>tester.update</Class>
<const>
</const>
<role>tester</role>
</application>
参数标签应该从第二个实例中完全删除
我正在搜索 tester.update,然后尝试删除第二次出现 tester.update 时向下 2 行的行
我尝试过类似的操作:
sed -i 'tester.update/{p;N;d}' file.txt
但这会从tester.update. 的两个实例中删除第二行
提前感谢您的帮助
【问题讨论】: