in reply to Re^3: search and extract lines which contain a word
in thread search and extract lines which contain a word
That prints out the lines containing either or both of "gateway" and "TIMESTAMP". Your if is equivalent to
if (/gateway/ || /TIMESTAMP/) { $count = $count + 1; print OUT; print "Extracting line ...\n"; }
However, I was under the impression you want lines containing both. If you want the lines containing both, your if would look like
if (/gateway/ && /TIMESTAMP/) { $count = $count + 1; print OUT; print "Extracting line ...\n"; }
As for excluding the listed names, one way is to start by building a regex using one of the following two methods:
my ($exclude_re) = map qr/$_/, join '|', map quotemeta, @names;
or
use Regexp::List qw( ); my $exclude_re = Regexp::List->new()->list2re(@names);
The just make sure the line doesn't match that regexp:
if (/gateway/ && /TIMESTAMP/ && !/$exclude_re/) { $count = $count + 1; print OUT; print "Extracting line ...\n"; }
|
|---|