如何使用sed删除多行上两个模式之间的内容?

时间:2017-04-04 04:22:31

标签: bash perl shell scripting scripting-language

这是输入

hai people<PATTERN>  we had
<PATTERN>a lot of fun<PATTERN>

writing scri pts
We will<PATTERN>
have more
<PATTERN>tomorrow<PATTERN>
Hurray!

需要

hai people<PATTERN>  we had

writing scripts
We will<PATTERN>
have more
Hurray!

对我来说,使用以下命令删除第一个模式匹配

sed '/PATTERN/{n;/PATTERN/d}' filename

1 个答案:

答案 0 :(得分:3)

grep -Pv '^<PATTERN>.*<PATTERN>$' input
hai people<PATTERN>  we had

writing scri pts
We will<PATTERN>
have more
Hurray!

使用sed,虽然它有点矫枉过正:

sed  '/^<PATTERN>.*<PATTERN>$/d' input