in reply to How to search for two strings/regex in one file
Stop looking through the file as soon as the 1st string is found. If the 1st string is found, start looking through the file from the beginning again. Stop looking through the file as soon as the 2nd string is found. Untested:
my $found_first = 0; my $found_second = 0; while (<LOG>) { if (/002389983/) { print "Looking for: 002389983\n Found it in file: $_\n"; $found_first = 1; last; } } if ($found_first) { seek LOG, 0, 0; while (<LOG>) { if (/002389983/) { print "Looking for: 29994339499\n Found it in file: $_\n"; $found_second = 1; last; } } } unless ($found_second) { print "Could not find the second string: 29994339499\n"; }
|
|---|