input.txt中:
blah1 blah2 start_pattern blah3 blah4 blah5 end_pattern blah6 blah7
我想input.txt成为:
blah1 blah2 end_pattern blah6 blah7
我尝试了以下,但它没有奏效.
sed -i "/start_pattern/,/end_pattern/{$!d}" input.txt
解决方法
This question处理您的问题:
$sed '/start_pattern/,/end_pattern/{/end_pattern/!d}' foo.txt blah1 blah2 end_pattern blah6 blah7