Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 我想删除文件中以特定模式开头的所有行_Bash_Sed_Printing - Fatal编程技术网

Bash 我想删除文件中以特定模式开头的所有行

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

我的输入文件包含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 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这将解决您的问题