What's the command line equivalent of: For every file that contains "AAA" within its contents, find "BBB" and replace it with "CCC"
Thus, the command would match and replace BBB in a file:
<html>
<head></head>
<body>
AAA
Hello world!
BBB
</body>
</html>
But Not in a开发者_开发技巧 file:
<html>
<head></head>
<body>
Don't match me!
BBB
</body>
</html>
Thanks in advance!
Something like grep -l AAA file-names | xargs sed -i .bak 's/BBB/CCC/g'
should work. In the future, you might want to ask questions like this on https://serverfault.com/ instead.
Using positive look behind also can do the trick s/(?<=AAA).*?(BBB)/CCC/g
.
精彩评论