查找包含特定字符串的文件并使用此字符串删除行 - SSH,SED

时间:2015-09-19 09:29:20

标签: bash sed

我有多个文件" header.php"在多个目录中。 其中一些包含字符串" ASDF1234"其中一些没有。

我想搜索所有" header.php"文件包含字符串" ASDF1234"并删除包含它的整行。

我怎么能用sed做到这一点?

1 个答案:

答案 0 :(得分:3)

您也可以尝试这种方式

find  -iname "header.php" -exec  sed -i '/ASDF1234/d' {} \;

<强>解释

   find -iname "header.php"  - It will find all header.php files
   -exec                     - Execute the sed command and passing the argument for all the header.php files
   sed -i '/ASDF1234/d'      - If the /ASDF1234/ content match delete the line.