Here are 2 sed commands to do the trick. If your input file looks like
1
2
3
4
5
6
7
8
We want to delete lines 3,4,5,6.
$ sed '/# My Comment Text/ {h;N;N;g}' file | tac | sed '/# My Comment Text/,+1d' | tac
1
2
7
8
The first sed command removes 2 lines after the matched line without deleting the matched line.
Then we will cancel the file and delete the matched line and the line after (which is the previous line in the regular file.
Cancel the input and we are done.
source
share