deelinux has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Scan Files - Match String
by haukex (Archbishop) on Jan 04, 2017 at 18:31 UTC | |
by deelinux (Novice) on Jan 04, 2017 at 18:47 UTC | |
|
Re: Scan Files - Match String (updated)
by haukex (Archbishop) on Jan 04, 2017 at 18:12 UTC | |
|
Re: Scan Files - Match String
by neilwatson (Priest) on Jan 04, 2017 at 18:02 UTC |