in reply to Re^2: extract last 1 min log and find a string
in thread extract last 1 min log and find a string

You need to put the file ReadBackwards.pm in D:/App/Perl/site/lib/File. Create a sub folder File if necessary

How big is the log file ? Gigabytes ?

poj

Replies are listed 'Best First'.
Re^4: extract last 1 min log and find a string
by ytjPerl (Scribe) on Jul 20, 2017 at 18:04 UTC
    Thanks! it is working. I have my codes as following:
    use File::ReadBackwards; use POSIX; my $success; my $items; my $earliest = strftime( "%Y-%m-%d %H:%M:%S", localtime( time()- 1 * 6 +0 ) ); $bw = File::ReadBackwards->new( '/Documents/Traning/Perl/output.txt' ) + or die "/Documents/Traning/Perl/output.txt $!" ; while ( defined( my $log_line = $bw->readline() ) ) { last if $log_line lt $earliest; if ($log_line =~ /EnableDelayedExpansion/i) { print $log_line; }else { print "error";} }
    My intention is to search the string in the logfile which is still loading every min, once I found string, print out this line.