简体   繁体   English

如何从所有文件中删除特定行?

[英]How to remove specific lines from all files?

I want to delete all lines begin with 'sometext' from many files: 我想从许多文件中删除所有以“ sometext”开头的行:

find . -name "*.php"|xargs -I {} sed -e '/^sometext/d' {}

But this put me output to console. 但这使我输出到控制台。 How to modify this files directly? 如何直接修改此文件?

使用sed的-i选项:

 sed -i -e '/^sometext/d' file

Tell sed to modify the files "in place": 告诉sed“就地”修改文件:

find . -name "*.php" | xargs sed -i '' -e '/^sometext/d'

Note that the blank '' after -i is required, otherwise a new copy with a default suffix will be created. 请注意, -i后面必须有空白'' ,否则将创建带有默认后缀的新副本。

Also note the pruning if your unnecessary -I in xaegs 如果不需要,请注意修剪-I in xaegs

您可以使用exec完成此操作:

find . -name "*.php" -exec sed -i '/^sometext/d' {} \;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从文件夹中的所有文件中删除带有特定字符串的行 - How to remove from all files in folder the lines with specific string 从文件中删除所有行,以特定字符串开头和结尾 - Remove all lines from a file, starting and ending with a specific string 从文本文件中删除所有空行,同时保持格式 - remove all empty lines from text files while keeping format 从目录中的所有文件中删除包含字符串的行 - Remove lines containing a string from all files in directory 如何仅删除文件的所有行中的前两个前导空格 - how to remove only the first two leading spaces in all lines of a files 如何从所有.xml文件中删除所有包含字符串的行? - How to delete all lines containing a string from all .xml files? Linux - 如何根据字段值从文件中删除某些行 - Linux - How to remove certain lines from a files based on a field value 在linux目录中的所有文件中显示特定行 - display specific lines in all files in a directory in linux 如何从所有行中删除最后一个字符,但前提是该字符是某个特定字符 - How to remove the last character from all lines but only if it is a certain character Linux:如何删除文件夹中除具有特定名称的文件之外的所有文件? - Linux: how to remove all the files in a folder except ones with specific names?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM