I would to like to delete all instances of a pattern which contain another specified pattern (conveniently on a new line):
MID:
Sample Input:
header
BEGIN:
1abc
7wurw
END:
BEGIN:
22xyz
MID:
34utov
END:
Desired Output:
header
BEGIN:
1abc
7wurw
END:
I'm looking for possible one liners. Any help would be appreciated.
Using GNU sed:
sed -e :a -e '/^BEGIN:/,/^END:/ { /END:/!{$!{N;ba};};/MID:/d;}' inputfile
For your input, it'd return:
header
BEGIN:
1abc
7wurw
END:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With