Parsing Log File help

Hi,

I am a newbie to scripting.

I have multiple log files (saved as .gz) in a directory that looks like this

01-01-2013 10:00 pn: 123
01-01-2013 10:00 sn: 987
01-01-2013 10:00 [1] Test1
01-01-2013 10:00 Result: Pass
01-01-2013 10:00 Time: 5:00
01-01-2013 10:00 [2] Test2
01-01-2013 10:00 Result: Fail
01-01-2013 10:00 Time: 10:00
01-01-2013 10:00 Sympton: Bad
01-01-2013 10:00 [3] Test3
01-01-2013 10:00 Result: Pass
01-01-2013 10:00 Time: 20:00

I need to go through all the .gz files in a particular direcory looking for only log files that have a result=fail with specifically "Test2" only. Then output this to another file ideally csv file so I can do some post processing.

I would like the output file to look like this
pn , sn , time to fail
123 , 987 ,10

.gz is normally used for gzip-compressed files; then search for matching lines with

gunzip -c *.gz | fgrep 'Result: Fail'

Otherwise replace gunzip -c with cat .
This loses the information in which file(s) it was found.

What if the log file has multiple fail results, but I want to check if this is Test2 and not Test3 and then print the time it took for Test2 before it failed?

01-01-2013 10:00 pn: 123
01-01-2013 10:00 sn: 987
01-01-2013 10:00 [1] Test1
01-01-2013 10:00 Result: Pass
01-01-2013 10:00 Time: 5:00
01-01-2013 10:00 [2] Test2
01-01-2013 10:00 Result: Fail
01-01-2013 10:00 Time: 10:00
01-01-2013 10:00 Sympton: Bad
01-01-2013 10:00 [3] Test3
01-01-2013 10:00 Result: Fail
01-01-2013 10:00 Time: 20:00

Please wrap your code in "code" tags (at the top of the Wiki editor)!
In Linux you can use

fgrep -B 1 -A 1 'Result: Fail'

The following awk searches for the given test:

awk '(n==2 && /Time:/) {printf "%s\n%s\n%s\n",bb,b,$0; n=0} (n==1) {if (/Result: Fail/) {b=$0; n=2} else {n=0}} (n==0 && $NF~test) {bb=$0; n=1}' test=Test2