Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using sed to delete range of lines except the end pattern

Tags:

sed

awk

input.txt:

blah1
blah2
start_pattern
blah3
blah4
blah5
end_pattern
blah6
blah7

I would like input.txt to become:

blah1
blah2
end_pattern
blah6
blah7

I tried the following, but it didn't work.

sed -i "/start_pattern/, /end_pattern/{$!d}" input.txt
like image 406
Springray Avatar asked May 19 '13 09:05

Springray


1 Answers

This question deals with your problem:

$ sed '/start_pattern/,/end_pattern/{/end_pattern/!d}' foo.txt
blah1
blah2
end_pattern
blah6
blah7
like image 129
Adrian Frühwirth Avatar answered Oct 06 '22 09:10

Adrian Frühwirth