簡體   English   中英

需要刪除前N行的grep結果文件

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM