I need to match two patterns in a log file and need to get the next line of the one of the pattern (out of two patterns) that is matched, finally need to print these three values in a single line.
Sample Log File:
2013/09/05 04:26:00 Processing Batch /fbc/dev/cebi/dod/9739867262
2013/09/05 04:26:02 Batch 9739867262 was successful
2013/09/05 04:26:02 Total Time = 3.13 Secs
2013/09/05 04:26:02 Repository API Time = 2.96 Secs
2013/09/05 04:26:02 File System Io Time = 0.06 Secs
2013/09/05 04:26:02 Doc Validation Time = 0.03 Secs
2013/09/05 04:26:02 Ending @ Thu Sep 05 04:26:02 EDT 2013
2013/09/05 08:18:10 Starting @ Thu Sep 05 08:18:10 EDT 2013
2013/09/05 08:18:10 Starting @ Thu Sep 05 08:18:10 EDT 2013
2013/09/05 08:18:10 Processing Batch /fbc/dev/cebi/dod/9844867675
2013/09/05 08:18:10 Processing Batch /fbc/dev/cebi/dod/9886743777
2013/09/05 08:18:16 Batch 9844867675 was successful
2013/09/05 08:18:16 Total Time = 6.00 Secs
2013/09/05 08:18:16 Repository API Time = 5.63 Secs
2013/09/05 08:18:16 File System Io Time = 0.05 Secs
2013/09/05 08:18:16 Doc Validation Time = 0.19 Secs
2013/09/05 08:18:16 Ending @ Thu Sep 05 08:18:16 EDT 2013
2013/09/05 08:18:18 Batch 9886743777 was successful
2013/09/05 08:18:18 Total Time = 8.27 Secs
2013/09/05 08:18:18 Repository API Time = 8.52 Secs
2013/09/05 08:18:18 File System Io Time = 0.08 Secs
2013/09/05 08:18:18 Doc Validation Time = 0.47 Secs
2013/09/05 08:18:18 Ending @ Thu Sep 05 08:18:18 EDT 2013
I have the numbers seperatly in file named cust_no.txt
9739867262
9844867675
9886743777
Taking these numbers as input I need to match following two patterns in the log file
- Processing Batch /fbc/dev/cebi/dod/
- Batch was successful
Following are required as output:
-> On the match of first pattern (i.e Processing Batch /fbc/dev/cebi/dod/<numbers in the cust_no.txt>
) I need to get the 2nd word i.e $2 .
-> On the match of second patterns (i.e Batch <numbers in the cust_no.txt> was successful
) I need to get the 2nd word i.e $2
-> And the 6th word ($6) on the next line after the match after the second pattern (i.e the line staring with Total Time
)
Desired output:
9739867262,04:26:00,04:26:02,3.13 Secs
9844867675,08:18:10,08:18:16,6.00 Secs
9886743777,08:18:10,08:18:18,8.27 Secs
In order get this I tried in the below way but this seems not to work:
awk -v cn=$cust_no '{{if ($0 ~ "Processing.*" cn) st=$2 && if ($0 ~ "Customer cn was successful" et=$2; getline; tt=$4} ; print st,et,tt}
'/^Processing/ { ..}'