如何使用sed删除与模式匹配的行及其后的行? [英] How to delete the line that matches a pattern and the line after it with sed?
本文介绍了如何使用sed删除与模式匹配的行及其后的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个看起来像这样的文件:
I have a file that looks something like:
good text
good text
FLAG bad text
bad text
good text
good text
good test
bad Text FLAG bad text
bad text
good text
我需要删除任何包含"FLAG" 的行,并且我总是也需要删除紧接在"FLAG"行之后的一行.
I need to delete any line containing "FLAG" and I always need to delete the one line immediately following the "FLAG" line too.
"FLAG"行不规则地出现,以至于我不能依靠任何种类的行号策略.
"FLAG" lines come irregularly enough that I can't rely on any sort of line number strategy.
有人知道如何用sed做到这一点吗?
Anyone know how to do this with sed?
推荐答案
使用 sed :
Using an extension of the GNU
version of sed:
sed -e '/FLAG/,+1 d' infile
它产生:
good text
good text
good text
good text
good test
good text
这篇关于如何使用sed删除与模式匹配的行及其后的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文