我正在尝试删除这个字符串
;document.write('<iframe src="http://google.com" scrolling="auto" frameborder="no" align="center" height="11" width="11"></iframe>');
跨目录(包括子目录)中的所有文件。
我知道我必须转义字符或使用正则表达式。但是我对正则表达式很糟糕。任何见解表示赞赏。
最佳答案
如果你想删除一个固定的字符串,你不需要使用正则表达式。您可以按原样将它放在 sed 命令中,但要选择一个不同于字符串中任何字符的分隔符(我在这里使用 #
):
str=";document.write('<iframe src="'"http://google.com" scrolling="auto" frameborder="no" align="center" height="11" width="11"></iframe>'"');"
find . -type f -exec sed -i.bk -e "s#$str##g" {} \;
关于linux sed 语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13749874/