Rodrick Brown wrote:
On Tue, Sep 9, 2008 at 3:23 PM, <[EMAIL PROTECTED]> wrote:
i want get the time specified in last line of the file.
For eg:
$tail -2 test.log
2008 aug 25 14:48:42.800 Sending ping message;
2008 aug 25 14:48:43.390 Sending ping message;
The file size is huge, so i dont want to read the entire file to get
the last line. Is there any way to get the last line of a file
directly in perl? i need to get the hour(14) and min(48) specified in
the last line of the file. can anybody help me on this?
You can mimic tail -1 using the following:
perl -nle 'push @l,$_; END { print $l[$#l] }' /tmp/filename
You don't have to save the entire file in an array just to capture the
last line:
perl -ne'$l = $_; END { print $l }' /tmp/filename
Or even:
perl -pe'$\=$_}{' /tmp/filename
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/