I'm trying to remove the lines between two patterns including the lines with the patterns themselves, if another pattern is found between them, but I'm not sure how to tackle it.
Say I have an input like the following and want to delete lines #6 to #11 because the pattern notthis
is found between the patterns start
and end
:
start
AHBUe3Ar5NoD
3EcuCcD2QCja
7VmlKFbD8Rbi
end
start
OgytsRhZbD8T
notthis
0PlcUh2RLvVW
tsz2S80SyW9p
end
start
dQ5qiZCvBqcK
SufdS40X1Sh2
B1cyNshOj2Z4
end
I changed what I thought I understood from this answer to something like this, but it doesn't work:
/^start$/{$!{N;/^start\n(.*\n)*notthis.*\n(.*\n)*end/d;ty;P;D;:y}}
Is it because N
only appends the line following the initial pattern ^start$
to the pattern space and ignores what follows? And what would be the correct way to achieve what I am trying to?