[英]Need to delete first N lines of grep result files
我正在尝试摆脱某些Wordpress安装中的黑客问题。
这个家伙在我的服务器上的多个文件的开头放了9行代码。。。我正在尝试使用grep和sed解决此问题。
我尝试着:
grep -r -l "//360cdn.win/c.css" | xargs -0 sed -e '1,9d' < {}
但是什么也没发生,如果我-0 from
xargs中删除-0 from
, the result of the files found are clean, but they are not overwriting the origin file with the
sed`结果, the result of the files found are clean, but they are not overwriting the origin file with the
,有人可以帮助我吗?
非常感谢!
您应该使用--null
在选项grep
命令输出NUL字节或\\0
在每个文件名后grep
输出。 -i.bak
sed
-i.bak
用于每个文件的内联编辑:
grep -lR --null '//360cdn.win/c\.css' . | xargs -0 sed -i.bak '1,9d'
直接遍历文件有什么问题¹?
你可能要添加-i
平的sed,使文件进行编辑我正地方
grep -r -l "//360cdn.win/c.css" | while read f
do
sed -e '1,9d' -i "${f}"
done
¹很好,如果文件中包含换行符之类的内容,则可能会遇到问题。 但是然后...如果您的网站包含带有换行符的文件,则可能仍然存在其他问题...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.