00018066: 13:33:19,Routd,15444,,3678800,0,,,7086 00018066: 13:33:19,Alert,15444,,3678800,0,,7086 00018066: 13:33:20,Cnnct,15444,,3678800,0,,7086 00018066: 13:33:20,Cnnct,15445,,3678800,0,,7086 00018066: 13:33:41,Routd,15444,,3678800,0,,7086,7800 00018066: 13:33:21,Routd,15444,,3678800,0,,7086,7801 #### #!/usr/bin/perl print "Please enter trace file name\n"; $tracefilename = ; chomp $tracefilename; print "Please enter agent extension\n"; $agentextension = ; chomp $agentextension; while (1) { print "Please enter time in 24 hour (e.g 1:00 PM would be 13:00:00)\n"; $time = ; chomp $time; if ($time =~/^(\d\d):(\d\d):(\d\d)/ ) { $phour = $1; $pmin = $2; $psec = $3; last; } # loop if incorrect format print "Incorrect time format. Please re-enter time in military format.\n"; } # print a spaces for better viewing print "\n"; print "\n"; #open tracefilename open (THATFILE, "$tracefilename") or die "cannot open $tracefilename: $!"; #read each line of file and grab line that has associated agent extension and time LINE: while () { next LINE if (!/^\d+: (\d\d):(\d\d):(\d\d)/ ); chomp ($_); # print "line = $_\n"; # look for agent extension in positions 6, 7, or 8 in trace line ($ext,$toext,$spext)=(split(/,/,$_))[6..8]; if( $ext==$agentextension or $toext==$agentextension or $spext==$agentextension) { ($hour,$min,$sec)=($1,$2,$3); $diffhour = 3600 * ($phour - $hour); $diffmin = 60* ($pmin - $min); $diffsec = ($psec - $sec); $sumdiff = abs ($diffhour) + abs ($diffmin) + abs ($diffsec); if ($sumdiff <= 2) { ($callid)=(split(/,/,$_))[2]; next LINE; #I want to keep track of each callid associated with agent extension and 2 second time stamp. #I noticed that the callid is in the 4th position } } } # reset filehandle to offset 0 from start of file (0) seek (THATFILE, 0, 0); # second loop to file, grabbing lines with associated CallID in 4th position. LOOP: while () { chomp ($_); ($pos4) = (split(/,/,$_)) [2]; if ($pos4 == $callid) { push (@array, $_."\n"); next LOOP; } } #sort array (@array) by time and line number print @array; close (THATFILE);