从bash替换XML中的字符串,而不写入正则表达式
我有一个大的平面文件,其中包含我要删除的重复字符串的许多实例:从bash替换XML中的字符串,而不写入正则表达式,xml,string,bash,replace,xml-parsing,Xml,String,Bash,Replace,Xml Parsing,我有一个大的平面文件,其中包含我要删除的重复字符串的许多实例: <content type="html"> <p> </p> <p>Jump around on couch, meow constantly until given food.</p> <p> </p> </summary> 如
<content type="html">
<p> </p>
<p>Jump around on couch, meow constantly until given food.</p>
<p> </p>
</summary>
如何在不编写正则表达式的情况下从bash中删除重复字符串?我使用了一个名为的工具,它不需要我编写任何正则表达式:
$ rpl '<p> </p>' '' /tmp/file
Really DELETE all occurences of <p> </p> (case sensitive)? (Y/[N]) Y
Replacing "<p> </p>" with "" (case sensitive) (partial words matched)
A Total of 55 matches replaced in 1 file searched.
使用brew安装rpl通过自制安装。在2分钟内完成。了解正则表达式后,它将是:
sed -i.bck 's~<p> </p>~~g' /tmp/file
由于它是xml,请查看。。我没有亲自使用过它,所以我不知道如何将它用于此案例…感谢您提供的解决方案。我已经更新了这个问题,试图更清楚地说明我想要实现什么,以及为什么RegExp可能不是满足我需求的最佳方法。
sed -i.bck 's~<p> </p>~~g' /tmp/file