# open a file my $filename = $ARGV[0]; open(debugfile, $filename) || die "Sorry, couldn't open file!"; while($line = <debugfile>) { if($line =~ /##BEEP/) # place the regular expression to match the +first line here { print $line; @firstLine = split(/\)/, $line); $firstLineTime = $firstLine[1]; @match = split (/##/, $firstLineTime); $Tic = $match[0]; $waitingForTargetStatement = 1; # print "$firstLineTime\n"; # print "$Tic\n"; next; } if($line =~ /Pick/ && $waitingForTargetStatement == 1) # place the + regular expression to match the second line here { $waitingForTargetStatement = 0; @secondLine = split(/\)/, $line); $secondLineTime = $secondLine[1]; @match = split (/##/, $secondLineTime); $Tic = $match[0]; $time = $secondLineTime - $firstLineTime; $time = $time/1000; print $line; # print "$Tic\n"; print "The time between the beep and the next pick location is + $time seconds\n"; # modify the print statement print "\n"; next; } # if($line =~ /##|\^\^|SYSMSG|DIALOG/) # place a regular expression + to include other desired content here. # { # print $line; # } }
EXAMPLE OF LOG: (8/20/09 7:59:28 PM EDT) 1524243: ##BEEP (375,2)## (8/20/09 7:59:28 PM EDT) 1524516: ##Two;Five; Pick (8/20/09 7:59:28 PM EDT) 1530337: ^^7 (8/20/09 7:59:28 PM EDT) 1530631: ^^5 (8/20/09 7:59:28 PM EDT) 1531465: ##BEEP (375,2)## (8/20/09 7:59:28 PM EDT) 1531639: ##Twenty Four;##;pp (8/20/09 7:59:44 PM EDT) 1534041: ^^ready (8/20/09 7:59:44 PM EDT) 1534177: ##Three;One; Pick (8/20/09 7:59:44 PM EDT) 1540464: ^^8 (8/20/09 7:59:44 PM EDT) 1540760: ^^8 (8/20/09 7:59:44 PM EDT) 1541590: ##BEEP (375,2)## (8/20/09 7:59:44 PM EDT) 1541884: ##Two;Three; Pick
In reply to How to match previous line by qnguyen
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |