#!/usr/bin/perl -w # hh, jan 2001: filter stdin lines for presence or absence of phrases my @must = () ; my @dont = () ; my @ormust = () ; my $usage = qq{ usage: filter.pl {+|-|:|++|--|::exp} [file]\t\t(c) 2001 hellweg\@snark.de +/-/: filter verbatim, ++/--/:: filter regexp + :must occur - :must not occur : :at least one of the ':'ed exp must occur output lines that contain all of the +patterns, none of the -patterns and/or at least one of the ':' patterns... often easier than grepping License to use, modify and redistribute granted to each and every lifeform on this planet (as long as credit to hellweg\@snark.de remains). No guarantee that 'filter' does or does not perform the way you want... } ; my ($par, $fil ) = (); $par = shift || die $usage ; while(defined($par)) { if($par =~ /^--(.+)/) { push @dont, $1 ; } elsif($par =~ /^-(.+)/) { push @dont, quotemeta($1) ; } elsif($par =~ /^\+\+(.+)/) { push @must, $1 ; } elsif($par =~ /^\+(.+)/) { push @must, quotemeta($1) ; } elsif($par =~ /^\:\:(.+)/) { push @ormust, $1 ; } elsif($par =~ /^\:(.+)/) { push @ormust, quotemeta($1) ; } else { $file = $par ; } $par = shift ; } my $ormust = 0 ; $ormust = "(" . join(")|(", @ormust). ")" if(scalar(@ormust)) ; if(defined($file)) { close(STDIN) ; open(STDIN, "<$file") || die "can not read $file\n" ; } LOOP: while() { next LOOP if($ormust && (! /$ormust/)) ; foreach $pat (@must) { next LOOP if(! /$pat/) ; } foreach $pat (@dont) { next LOOP if( /$pat/) ; } print ; }