Grep using perl -
i'm trying grep multiple patterns log file using perl. first pattern i'm getting desired matching pattern via read variable($1,$2..). next pattern read variable returning previous value not value matching sec pattern.
here code:
$tmp = `grep "solo_video_channel_.*(0): queueing" $log`; chomp($tmp); $tmp =~ m/(.*):.*solo_video_channel_write(.*): queueing page (.*).*/; $chnl = $2; $page = $3; $timestamp = $1; $tmp1 = `grep "(0): dump go" $log`; chomp($tmp1); $tmp1 =~ m/(.*): solo_video_channel_write(0): dump go/; $dmp = $1; print "dump go time = $1\n";
tmp1's value after grep coming expected. $1 value remains same previous one. suggestions?
always create sure verify regex matched before using captured variable.
additionally, there no reason shell out grep. utilize perl's file processing instead:
use strict; utilize warnings; local @argv = $log; while (<>) { chomp; if (/solo_video_channel_.*\(0\): queueing/) { if ( ( $timestamp, $chnl, $page ) = m/(.*):.*solo_video_channel_write(.*): queueing page (.*).*/ ) { print "$. - $timestamp, $chnl, $page\n"; } } if ( ($dmp) = m/(.*): solo_video_channel_write\(0\): dump go/ ) { print "dump go time = $dmp\n"; } }
note, first set of if's combined single if statement, left now.
perl
No comments:
Post a Comment