I use this
cat foo.txt | sed '/bar/d'
to remove lines containing the string bar
in the file.
I would like however to remove those lines and the line directly after it. Preferably in sed
, awk
or other tool that's available in MinGW32.
It's a kind of reverse of what I can get in grep
with -A
and -B
to print matching lines as well as lines before/after the matched line.
Is there any easy way to achieve it?
Best Answer
If you have GNU sed (so non-embedded Linux or Cygwin):
If you have
bar
on two consecutive lines, this will delete the second line without analyzing it. For example, if you have a 3-line filebar
/bar
/foo
, thefoo
line will stay.