删除包含两个字符串的行 [英] Delete lines that contain two strings
本文介绍了删除包含两个字符串的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 sed
删除文本文件中的某些行.我只想删除包含两个字符串的行.命令 \ |
等效于布尔值 OR
.布尔运算符 AND
的命令是什么?
I am trying to delete some lines in a text file using sed
. I only want to delete lines that contains two strings. The command \|
is equivalent to the boolean OR
. What is the command for the boolean operator AND
?
我正在寻找这样的东西:
I am looking for something like this:
sed '/strA'AND'strB/d' file.txt
推荐答案
这可能对您有用(GNU sed):
This might work for you (GNU sed):
sed '/strA/!b;/strB/d' file
如果该行不包含 strA
纾困.如果包含并且还包含 strB
,请将其删除.
If the line does not contain strA
bail out. If it does and it also contains strB
delete it.
这篇关于删除包含两个字符串的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文