Bash 我想删除文件中以特定模式开头的所有行
我的输入文件包含3000行Bash 我想删除文件中以特定模式开头的所有行,bash,sed,printing,Bash,Sed,Printing,我的输入文件包含3000行 system="This is nice" system="Add some crazy word" system="Some crazy word" system="Add another pattern" system="The parek went home" system="Add Ola phradse" system="The car is nice" 我想删除所有在system=”之后有“Add”一词的行 所以输入文件的结尾是 system="This
system="This is nice"
system="Add some crazy word"
system="Some crazy word"
system="Add another pattern"
system="The parek went home"
system="Add Ola phradse"
system="The car is nice"
我想删除所有在system=”之后有“Add”一词的行
所以输入文件的结尾是
system="This is nice"
system="Some crazy word"
system="The parek went home"
system="The car is nice"
您可以在终端中使用
sed '/^system="Add/ d' < text.txt > newtext.txt
sed'/^system=“Add/d'newtext.txt
您可以在终端中使用
sed '/^system="Add/ d' < text.txt > newtext.txt
sed'/^system=“Add/d'newtext.txt
请尝试以下内容,并告诉我这是否有帮助
解决方案1:在此处使用awk
awk '!/system="Add/' Input_file
说明:搜索没有system=“Add in”的行,如果是,则打印当前行
解决方案2:在此处使用grep
grep -v '^system="Add' Input_file
解释:使用grep的
-v
选项,该选项将省略正则表达式匹配的所有行,就像我给出了一行,从system=“Add
开始,然后跳过它。请尝试以下操作,并让我知道这是否有帮助
解决方案1:在此处使用awk
awk '!/system="Add/' Input_file
说明:搜索没有system=“Add in”的行,如果是,则打印当前行
解决方案2:在此处使用grep
grep -v '^system="Add' Input_file
解释:使用grep的-v
选项,该选项将省略正则表达式匹配的所有行,就像我从system=“Add
开始给出了一行,然后跳过它。sed'/^system=“Add/d”file.txt>new.txt这将解决sed'/^system的问题=“添加/d'file.txt>new.txt这将解决您的问题