我尝试从objump过滤转储,而我目前仍在过滤某些所需的行。
我现在有这样的事情......
many lines with pattern1 I dont need
line I don't need with pattern1
line I don't need with pattern1
line with pattern1 I need because the NEXT LINE matches the pattern2
line with pattern2
line with pattern1 I need because the NEXT LINE matches the pattern2
line with pattern2
line with pattern2
line I don't need with pattern1
line I don't need with pattern1
many lines with pattern1 I dont need
所以问题是,我需要删除每一行,包括带有pattern2的行,而* 只保留pattern2后面带有pattern1 的行。我需要以通用的方式做到这一点。 (我正在制作一个剧本)。
非常感谢您的帮助。
答案 0 :(得分:0)
这个awk应该做你想做的事情
$ awk '/pattern1/{k=$0;next}/pattern2/&&k{print k};{k=0}' file
line with pattern1 I need because the NEXT LINE matches the pattern2
line with pattern1 I need because the NEXT LINE matches the pattern2
我们在变量pattern1
中存储与k
匹配的行,并跳过其余的命令
如果某一行符合pattern2
且变量k
不为零,那么我们会打印存储的行。
如果行与pattern1
答案 1 :(得分:0)
您可以尝试此sed
,
sed -n '/pattern1/{N; /\n.*pattern2/!{D;b};p}'