How can I use sed to delete multiple lines when the pattern matches and stops before the first blank line?
1 answer
You can do it:
sed '/STARTING_PATTERN/,/^$/d' filename
This will select all lines starting with STARTING_PATTERN
, up to an empty line ^$
, and then remove those lines.
To edit files in place, use the option -i
.
sed -i '/STARTING_PATTER/,/^$/d' filename
Or using awk
:
awk 'BEGIN{f=1} /STARTING_PATTERN/{f=0} f{print} !$0{f=1}' filename
+7
source to share