in reply to How to search for two strings/regex in one file
(You may wish to tweak this if you've file names with newlines)grep -l 002389983 * | xargs grep -l 29994339499
Anyway, your code only checks if a line matches against both patterns, not a file. You'll have to rewind your file and check each line again with the second regexp. Or just check each line twice. Something like:
open my $fh, "<", $File::Find::name or die; my ($f1, $f2); while (<$fh>) { $f1 ||= /02389983/; $f2 ||= /29994339499/; last if $f1 && $f2; } if ($f1 && $f2) { ... Both patterns found ... }
|
|---|