in reply to Need help in extracting timestamp from the line in a file

Hello jayu_rao, and welcome to the Monastery!

If your log file is very large, you should consider using the module File::ReadBackwards, which is designed for this kind of task. Here is a code outline (skeleton) to get you started (you need to fill in the parts marked ...):

use strict; use warnings; use File::ReadBackwards; my $log = ...; my $fh = File::ReadBackwards->new($log) or die "Cannot read '$log': + $!"; my $found = 0; while (my $line = $fh->readline) { if ($line =~ /.../) # Identify a JVM line and capture the time +stamp { ...; # Re-format the timestamp and export it $found = 1; last; } } warn "No log entry found\n" unless $found;

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: Need help in extracting timestamp from the line in a file
by jayu_rao (Sexton) on Mar 09, 2015 at 16:30 UTC
    Thanks much Athanasius. I had used read backwards :-) and needed assistance in extracting the timestamp. Can you please look at the regex that I have come up with, in my code and suggest what is it that I am doing wrong?