Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

removing multple line base on regex search

Tags:

sed

how can I remove number of line based on regex search? for example : if i have a file :

aaa
bbb
ccc
ddd
bbb
eee

I would like to remove the line that contains "bbb" string and the line after it . so the result should look like :

aaa
ddd
like image 434
Gur Arie Kamelo Avatar asked Nov 30 '25 04:11

Gur Arie Kamelo


1 Answers

addr1,+N Will match addr1 and the N lines following addr1.

$ sed '/bbb/,+1d' file.txt 
aaa
ddd
like image 177
kev Avatar answered Dec 02 '25 03:12

kev



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!