Hi I want to search some logs and have the created the below, but match fails. (newish to scripting) The text is similar to the below, and I want to match on current date (no time) and then on ERROR or WARN Example text 2017-01-04 08:14:19,753 - 08:14:19,752 WARN 2017-01-04 08:14:19,753 - 08:14:19,752 ERROR Its not matching, but does if I use just the date, What I want is the date anything in between and then on the ERROR or WARN, if anyone can shed some light that would be good or an easier way. Thanks Dee
MyVariables $MYFOLDER = "/tmp/logs" #Severity Levels $SLEVEL1 = "ERROR"; $SLEVEL2 = "WARN"; #Mycustom Date - this gives 2017-01-04 $datestring = strftime "%Y-%m-%d", localtime; #MyMatches Pattern #$match1 = "^$datestring\s+\d{2}:\d{2}:\d{2},\d{3}\s+-\s+\d{2}:\d{2}:\ +d{2},\d{3}\s+$SLEVEL1"; sub MyScanLogs { @files = `find $MYFOLDER -name "*.log"`; foreach $file(@files) { open FILE, "$file" or die "Unable to open files"; while(<FILE>) { if ($_ =~ /$match1/) { print "$file $_\n"; } } } } MyScanLogs
In reply to Scan Files - Match String by deelinux
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |