Sed or Grep to delete line containing patter plus extra line

I'm new to using sed and grep commands, but have found them extremely useful. However I am having a hard time figuring this one out:

Delete every line containing the word CEN and the next line as well.
ie. test.txt

blue
324 CEN
green
red
blue
324 CEN
green
red
blue

to produce:

blue
red
blue
red
blue

I can delete the first line using either:

sed '/CEN/ d' test.txt 

or

grep -v 'CEN' test.txt

I tried to extend this with sed by adding

 
sed '/CEN/,2d' test.txt

But this didn't work as well.
There is nothing to use as a marker in the second line I want to delete so I can't run two of these commands in series.

Any help would be greatly appreciated.

Hi

sed '/CEN/{N;d;}' test.txt

Guru.

1 Like

Works well, thanks!