in reply to
Extracting Log File data for a given date range
A solution using Date::Parse.
#!/usr/bin/perl
use strict;
use warnings;
use Date::Parse qw/ str2time /;
#my ($start, $end) = map str2time($_), qw/ 01-Dec-2011 11-Dec-2011 /;
my ($start, $end) = map str2time($_), @ARGV;
while (<DATA>) {
(my $date = (split /,/)[3]) =~ s/_.+//;
my $time = str2time( $date );
print if $start <= $time && $time <= $end;
}
__DATA__
ABC01, 91XYZ889=_=SOMEBODY.NAME@DOMAIN.COM, HighPriority, 02-Dec-2011_
+00.34.51, bigFatLog_02-Dec-2011_00.34.06.log
ABC03, 93XYZ272=_=SOMEBODY.NAME@DOMAIN.COM, HighPriority, 07-Dec-2011_
+09.21.58, bigFatLog_07-Dec-2011_09.20.57.log
ABC02, 93XYZ807=_=SOMEBODY.NAME@DOMAIN.COM, HighPriority, 08-Dec-2011_
+23.00.15, bigFatLog_08-Dec-2011_22.59.34.log
ABC05, 91XYZ525=_=SOMEBODY.NAME@DOMAIN.COM, HighPriority, 10-Dec-2011_
+10.01.36, bigFatLog_10-Dec-2011_10.01.00.log
ABC01, 93XYZ252=_=SOMEBODY.NAME@DOMAIN.COM, HighPriority, 12-Dec-2011_
+11.58.23, bigFatLog_12-Dec-2011_11.57.20.log
ABC03, 93XYZ543=_=SOMEBODY.NAME@DOMAIN.COM, HighPriority, 12-Dec-2011_
+23.34.07, bigFatLog_12-Dec-2011_23.33.23.log
ABC04, 92XYZ066=_=SOMEBODY.NAME@DOMAIN.COM, HighPriority, 13-Dec-2011_
+01.00.31, bigFatLog_13-Dec-2011_00.59.29.log
ABC05, 93XYZ184=_=SOMEBODY.NAME@DOMAIN.COM, HighPriority, 13-Dec-2011_
+01.54.41, bigFatLog_13-Dec-2011_01.54.04.log
This assumes there are no embedded commas in the data, so it is safe to just
split on the comma. Otherwise, a module for parsing comma separated values like
Text::CSV_XS would be needed to parse the log.
And this is how I called it from the command line:
C:\Old_Data\perlp>perl t33.pl 20111201 20111211