Can we assume that each pattern matches within a single line? If so, then lets have @matcharray an array of qr// expressions, ordered by how often we expect a match - commonest first.
That all means you can read the input file line by line and print that line to an output file if a match is found:
Once a match is found, the line is printed to output (with the assumption that print succeeds) and further match tests are skipped.my @matcharray = map {qr/$_/} ( "all", "your", "[patterns]", ); open my $fh, '<', '/path/to/original/file' or die $!; open my $of, '>', '/path/to/filtered/file' or die $!; { local $_; while (<$fh>) { for my $pat (@matcharray) { /$pat/ and print $of $_ and last; } } }
After Compline,
Zaxo
In reply to Re: Usage of grep on a file
by Zaxo
in thread Usage of grep on a file
by tsk1979
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |