0

我需要从大约 1.5k 个文件中删除或注释掉以下内容,并且在执行此操作时遇到了很多麻烦。我已经用 perl find/replace 尝试了所有我能想到的东西,但没有得到任何结果。任何有关方法的建议都会有所帮助。它上方和下方的选项卡包含针对每个 xml 分支更改的属性,因此我不能使用它们来查找/替换。我已经尝试了我能想到的每一种组合,但没有得到任何结果。当我尝试查找/替换*'s 的字符串时,我收到一个错误,指出参数列表太长。如果我尝试在空白行和 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.

******************************************************
4

2 回答 2

0

那么触发器运算符呢?

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

请参阅perlop中的范围运算符。

于 2012-05-31T16:58:27.763 回答
0

Slurps 整个文件,以便您可以匹配多行:

perl -i~ -0777pe's/^\*{54}\n.*?^\*{54}\n//m' file
于 2012-05-31T18:03:56.430 回答