Nik Nik - 12 days ago 5x
Perl Question

remove lines after pattern in multiple files

I have the following command

find ./ -type f -exec perl -pi -e 's/<pattern>//g' '{}' \;

it works well and remove the pattern, but how can I remove the pattern, the line it is on, and
lines after?


It's more brute force than elegant, but I think this will remove the line with the matching pattern and the line following it.

find ./ -type f -exec perl -i -e '$x=0 ; while (<>) {if ($_ =~ /<pattern>/) { $x++; next; }; if ($x) { $x=0; next; }; print "$_";}' {} \;