【发布时间】:2014-02-03 11:11:35
【问题描述】:
我想在大文件(大约 900 MB)中搜索和替换。我在网上搜索了几个小时。
一般来说有两种适合的工具,sed 和 perl。
sed 的多行语法似乎很复杂,所以我尝试了 perl。
我的输入数据如下所示:
K 13
svn:mergeinfo
V 498
/code/branches/TEST_ENVIRONMENT_OBC/Implementation//SpecificComponents/SUV/config/TEST:4670-4976
/code/tags/QR_20131111/Implementation/SpecificComponents/SUV/config/TEST:4669
/code/tags/QR_20131211/Implementation/SpecificComponents/SUV/config/TEST:5138
/code/trunk/Implementation/SpecificComponents/SUV/config/OBC:4669-4949
/code/trunk/Implementation/SpecificComponents/SUV/config/TEST:5137-5273
PROPS-END
我想更改 svn:mergeinfo 块并替换部分路径。
所以我为 perl 写了一个小的正则表达式。
perl -0pe 's/^svn:mergeinfo\nV (\d+)\n(?:\/code(\/(?:branches|tags|trunk)(?:.|\n)+))+\nPROPS-END/svn:mergeinfo\nV \1\n\2\nPROPS-END/m'
到目前为止它工作正常,但输出数据中的路径仅在第一次出现时更改。
K 13
svn:mergeinfo
V 498
/branches/TEST_ENVIRONMENT_OBC/Implementation//SpecificComponents/SUV/config/TEST:4670-4976
/code/tags/QR_20131111/Implementation/SpecificComponents/SUV/config/TEST:4669
/code/tags/QR_20131211/Implementation/SpecificComponents/SUV/config/TEST:5138
/code/trunk/Implementation/SpecificComponents/SUV/config/OBC:4669-4949
/code/trunk/Implementation/SpecificComponents/SUV/config/TEST:5137-5273
PROPS-END
我需要更改什么来替换所有出现的路径?
不需要使用perl来解决问题。
【问题讨论】: