hplodur hplodur - 5 months ago 12
Perl Question

remove lines perl with multiple search patterns

I'm trying to find a way to use perl to remove lines that contain:

errors:
mirror
raid*
pond


I've managed to find:

perl -pi -e "s,errors:,,"


Is there a way to specify all patterns that I'm looking for in one command?

Answer

Since you mention Perl you can use:

perl -ne 'print unless /errors:|mirror|raid\*|pond/'

Alternative you can use sed or grep:

sed '/errors:\|mirror\|raid\*\|pond/d'

Or grep with re-verse:

grep -v 'errors:\|mirror\|raid\*\|pond'

You can add the -inplace flag to both sed and Perl

Comments