需要从xml文件中删除大量文本,使用perl find / replace时无法获取任何内容

时间:2012-05-31 16:41:25

标签: xml perl cmd

我需要从大约1.5k文件中删除或注释掉以下内容,并且在执行此操作时遇到了很多麻烦。我已经尝试过perl find / replace所能想到的一切,但我没有到达任何地方。任何有关方法的建议都会有所帮助。它上面和下面的选项卡包含为每个xml分支更改的属性,因此我无法使用它们来查找/替换。我已经尝试了我能想到的每一种组合,而且无法实现任何目标。当我尝试查找/替换*的字符串时,我收到一个错误,指出参数列表太长。如果我尝试在空行和1 *上找到/替换它,它也不会捡起它。几个例子:

perl -pi -e 's/\n\*/<!--/g' */*/*.log 
perl -pi -e 's/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/<!--/g' */*/*/log
perl -pi -e 's/>\n\*/><!--/'g */*/*.log (this one tries finding the end of the tag above it)

******************************************************

This system is for the use of authorized users only.
Individuals using this computer system without
authority, or in excess of their authority, are
subject to having all of their activities on this
system monitored and recorded by system personnel.

In the course of monitoring individuals improperly
using this system, or in the course of system
maintenance, the activities of authorized users may
also be monitored.

Anyone using this system expressly consents to such
monitoring and is advised that if such monitoring
reveals possible evidence of criminal activity, system
personnel may provide the evidence of such monitoring
to law enforcement officials.

******************************************************

2 个答案:

答案 0 :(得分:0)

触发器操作符怎么样?

perl -ne 'print unless /^\*+/ ... /^\*+/'

请参阅Range Operators中的perlop

答案 1 :(得分:0)

覆盖整个文件,以便您可以跨多行匹配:

perl -i~ -0777pe's/^\*{54}\n.*?^\*{54}\n//m' file