Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux sed remove 2 lines with pattern

Tags:

bash

sed

I know how to remove all lines contening a pattern with

sed -i '/pattern/d' file

But how should I remove the line AND the next line ?

For example, with the following file, I want to remove all 'Apple' and next fruit

Apple
Peach
Lemon
Apple
Banana
Peach

Expected Output:

Lemon
Peach

Someone know how to do that ?

like image 736
APianist Avatar asked Nov 23 '25 03:11

APianist


1 Answers

Could you please try following(written and tested in GNU sed).

sed '/Apple/,+1 d' Input_file
like image 193
RavinderSingh13 Avatar answered Nov 24 '25 20:11

RavinderSingh13



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!