Reputation: 25
I'm trying to use sed to delete line that matches specific pattern and all the subsequent lines until another pattern is found.
For example:
This is a line I want to delete,
this is second line that should be deleted.
And this is stop-pattern which should terminate deletion.
I want to delete the whole above paragraph giving sed two patterns /delete,/ (which is the starting pattern and whole line containing that pattern should be deleted) and /deletion./ (which is the pattern which determines the point where to stop deleting).
How do I write sed command which can accomplish that?
Upvotes: 1
Views: 688
Reputation: 626689
You may use
sed '/delete,/,/deletion\./d' file > outfile
Here,
/delete,/,/deletion\./
tells sed
to match a portion of text between (and including) the lines, starting with one contraining delete,
and ending with the line having deletion.
(note .
must be escaped to match a literal dot)d
tells sed
to remove that block of lines.See an online sed
demo.
Upvotes: 2