Reputation: 3187
I am very new to shell script.
How can I delete multiple lines when the pattern is matched and stop deleting until the first blank line is matched?
Upvotes: 4
Views: 11510
Reputation: 3223
You can do this:
sed '/STARTING_PATTERN/,/^$/d' filename
This will select all the lines starting from STARTING_PATTERN
upto a blank line ^$
and then delete those lines.
To edit files in place, use -i
option.
sed -i '/STARTING_PATTER/,/^$/d' filename
Or using awk
:
awk 'BEGIN{f=1} /STARTING_PATTERN/{f=0} f{print} !$0{f=1}' filename
Upvotes: 11