in reply to Extracting Log File data for a given date range
A solution using Date::Parse.
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.#!/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
And this is how I called it from the command line: C:\Old_Data\perlp>perl t33.pl 20111201 20111211
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Extracting Log File data for a given date range
by vishi (Beadle) on Dec 14, 2011 at 05:39 UTC | |
by Anonymous Monk on Dec 15, 2011 at 21:51 UTC | |
by Anonymous Monk on Aug 28, 2012 at 08:56 UTC | |
by Anonymous Monk on Aug 28, 2012 at 09:21 UTC | |
by Anonymous Monk on Jun 11, 2014 at 17:57 UTC |
In Section
Seekers of Perl Wisdom