如果匹配模式xxx
,则应删除文本文件中的所有行,除非该行包含yyy
。
示例输入(文字):
- 1 The first line does not contain the pattern. - 2 The second line does contain the pattern xxx but still can't be deleted because of yyy. - 3 The third line should be remove because it only contains xxx.
所需的输出(文字):
- 1 The first line does not contain the pattern. - 2 The second line does contain the pattern xxx but still can't be deleted because of yyy.
答案 0 :(得分:1)
这应该有效(未经测试)
awk '!/xxx/ || /yyy/'
答案 1 :(得分:0)
如果行号是输入/输出的一部分
$ awk '!/xxx/ || /yyy/ {$1=++c;print}' lines
1 This first line does not contain the pattern.
2 This second line does contain the pattern xxx but still can't be deleted because of yyy.
如果不需要行号,请使用@ rici的解决方案