Use SED to delete all lines between a single repeating pattern

I’d like to use sed to delete all lines between a pattern that repeats throughout a text file.

File looks like this:

SET ENG_1
blah blah
blah blah
SET ENG_2
blah blah
blah blah

There are multiple SET ENG_# lines, but I never know what the number on the end will be. Here is what I have tried:

sed -i "/SET ENG_/,/SET ENG_/{//!d}" $MYFILE

It only works on the first occurence, so I get this output:

SET ENG_1
SET ENG_2
blah, blah
blah blah

Do I need to have sed start from the bottom of the text file, somehow?


Source: unix

Leave a Reply