I have a log file containing XML Messages.Each XML Message is accompanied with a timestamp.I need to count the the number of messages that get logged in a particular timeinterval.Is there any command/Syntax to achieve this.
Thanks for ur reply.Actually there is no need to parse my XML.Each XML message is accompanied with a timestamp value(it is not a XML field).I just need to count the no of messages within a particular time interval using shell scripting.
#!/usr/bin/perl
use strict;
use warnings;
my ($start,$end) = @ARGV;
unless ($start =~ /^\d{4}-\d\d-\d\d\s+\d\d:\d\d:\d\d$/ &&
$end =~ /^\d{4}-\d\d-\d\d\s+\d\d:\d\d:\d\d$/) {
die qq{Usage: perl path/to/count.pl "start" "end"
start and end = "YYYY-MM-DD HH:MM:SS" including quotes};
}
my $count = 0;
(my $s = $start) =~ tr/- ://d;
(my $e = $end) =~ tr/- ://d;
open (my $in, 'path/to/input_file') or die "$!";
while(<$in>){
if (/^(\d\d\d\d)-(\d\d)-(\d\d)\s+(\d\d):(\d\d):(\d\d)/) {
$count++ if ($e ge "$1$2$3$4$5$6" && "$1$2$3$4$5$6" ge $s);
}
}
close $in;
print "Number of messages found between $start and $end: $count\n";