learingperl01
MIS
Hello hoping someone could help me. I am trying to create a script which searches through all files in a directory for a string, if the string is found I want it to look through the entire file which it found the first string and look for a second string. Right now I have the code below, but it looks like when it tries to match the second string it's comparing the regex against the result/output of the first regex not against the entire file which it found the fist regex in.
How can I make my script search for a string against a file if it finds the string in that file then search that entire file once again for the second string.
thanks for the help.
How can I make my script search for a string against a file if it finds the string in that file then search that entire file once again for the second string.
thanks for the help.
Code:
sub edits() {
if ( -f and /^Khlog.08$/ ) {
foreach ( $File::Find::name ) {
open(LOG, "< $File::Find::name") or die "Could not open file $_: $!";
while ( <LOG> ) {
my $LINE = $_;
if ( $LINE =~ m/002389983/ ) {
print "Looking for: 002389983\n Found it in file: $LINE\n";
if ( $LINE =~ m/29994339499/ ) {
print "Looking for: 002389983\n Found it in file: $LINE\n";
}
else {
print "Could not find the second string: 002389983\n";
}
}
}
}
}