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, |
In reply to Re: Need help in extracting timestamp from the line in a file
by Athanasius
in thread Need help in extracting timestamp from the line in a file
by jayu_rao
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |