【发布时间】:2011-12-07 15:29:15
【问题描述】:
我想递归替换“blah blah blah” 在我的许可证区域中什么都没有:
#region License
blah blah blah
blah blah blah
#endregion
应该替换为
#region License
#endregion
这应该适用于我在某个目录中的所有 .cs 文件(递归)。我用 sed 试过这个,但是因为我在 Windows 上,所以我在行尾方面遇到了一些问题。如何使用 perl(或 python)或 Windows 原生的东西来做到这一点?
编辑:这是我想出的解决方案,感谢这里的所有人!:
#/bin/bash
list=`find . -name '*.cs' -o -name '*.h' -o -name '*.cpp'`
for i in $list
do
perl -i~ -ne 'if (/#region License/../#endregion/) {print if /#(?:end)? region/;next};print' $i
done
【问题讨论】:
-
我希望这是你自己的许可证,而不是别人的......
-
我这样做是为了避免两个分支之间的大规模合并冲突,其中所有文件的许可证文本都已更改