I want to remove this and next paragraph when criteria is met in this
paragraph. If expressed in sed, it'll be:
sed -paragraph_mode '/criteria/{N; d; }'
I tried the following in Perl, but neither works:
perl -n000e 'if (/criteria/) { next; next; }'
or,
perl -n000e '
if (/criteria/) { next; $skip_next=1; }
if ($skip_next) { next; $skip_next=0; }
'
Please help.
Thanks
This will output nothing. If you're using -n you need to print the lines
yourself.
The Perl equivalent of sed's 'N' (when using -n or -p) is '$_ .= <>'.
Since you are just throwing the line away, you don't need to append it
to $_. So that gives us
perl -n000e 'if (/criteria/) { <>; next; } print;'
I was going to suggest using 's2p', but it understands a rather limited
dialect of 'sed' and produces completely unreadable Perl, so, um, don't
:).
Ben
--
'Deserve [death]? I daresay he did. Many live that deserve death. And some die
that deserve life. Can you give it to them? Then do not be too eager to deal
out death in judgement. For even the very wise cannot see all ends.'
b...@morrow.me.uk
>> I want to remove this and next paragraph when criteria is met in this
>> paragraph. If expressed in sed, it'll be:
>>
>> sed -paragraph_mode '/criteria/{N; d; }'
>>
>> . . .
>
> The Perl equivalent of sed's 'N' (when using -n or -p) is '$_ .= <>'.
> Since you are just throwing the line away, you don't need to append it
> to $_. So that gives us
>
> perl -n000e 'if (/criteria/) { <>; next; } print;'
Thanks a lot. It works great. (yeah, I was so focusing on isolating the
question out of my code that I forgot about to include the print).
Thanks