in reply to Re^3: extract last 1 min log and find a string
in thread extract last 1 min log and find a string
My intention is to search the string in the logfile which is still loading every min, once I found string, print out this line.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";} }
|
|---|