Using “sed” to delete a line containing something and the next line

  • A+
Category:Languages

Assume a file with the following contents:

good good bad next of baaaad good 

I want to use sed to delete lines which contain "bad" and the next line of these lines. In above example I want to delete line 2 and line 3.

How can I do that?

I tried this, but it doesn't work:

ebra@him:/tmp$ cat iio | sed -e "s//n.*bad.*/n.*//" good good bad next of baaaad good 

 


In sed:

sed '/bad/{N;d}'  Input_file 

Following awk may help you here.

awk '/bad/{getline;next} 1'  Input_file 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: