2013-03-28 26 views

回答

2

已經有很多類似的答案。我想補充一點,如果你想匹配字左右this is a line containing a keyword但不this is a line containing someoneelseskeyword,那麼你最好加括號:

sed -i '/\<keyword\>/d' *.txt 
0

肯定的:

for x in files* 
do 
    grep -v your_pattern "$x" > x && mv x "$x" 
done 
1

我現在不能測試此權利,但它應該讓你開始

find /path/to/folder -type f -exec sed -i '/foo/d' {} ';' 
  • 在目錄中找到的文件中包含這些文件/path/to/folder
  • 發現線foo
  • 從那些fil中刪除那些行es
0

sed -i'/ keyword/d'* .txt - 在您的目錄中運行。

的sed - 流編輯器,在這裏使用它在單個文件

刪除線

-i選項:使輸入permenent更改文件

「/ keywprd /」:指定圖案或要在文件中搜索的鍵

選項d:通知sed需要刪除匹配行。

* .txt:只是告訴sed使用目錄中的所有文本文件作爲
處理的輸入,您可以像我一樣指定個人或擴展名,如* .txt。

0

試試這個:

find your_path_filename |xargs sed -i '/key_word/d' 
+0

如果你有空格的文件名,在'xargs'中使用'find'和'-0'時需要'-print0'選項。 'find your_path_filename -print0 | xargs -0 sed -i'/ key_word/d'' – Julien

相關問題