Re: In sed, how do you delete just the first matching line in a block of lines?
Xicheng Jia wrote:
> Dave S. wrote:
> > Xicheng,
> >
> > Your solution did not work when I incorporated it into my original
> > script, but it DID work as a separate script so I'm putting it in a
> > separate script that makes a second pass on the output.
>
> Maybe you can try this:
>
> sed '/switch/,/case/!{/case\|default/i\
> \tbreak;
> }'
>
> or use perl:
or probably:
perl -pe '
s/(\s*)(case|default)/$1\tbreak;\n$1$2/
if not /switch/../case/'
awk '
/switch/,/case/ { print; next }
/case|default/ { print "\tbreak;" }1'
Xicheng
|