Get the sum of values in between begin and end in the file

Hi All,
test file

Begin [test.sh] Script Run at Thu Mar 14 09:24:16 PDT 2013
tst_accounts: ws zip: WS_out_20130313.tar.gz dat: test_20130313.dat count: 63574 loaded: xx pre-merge: xx post-merge: xx timestamp: Thu Mar 14 09:30:42 PDT 2013
tst_accounts: ws zip: WS_out_20130313.tar.gz dat: s_20130313.dat count: 168217 loaded: xx pre-merge: xx post-merge: xx timestamp: Thu Mar 14 09:47:05 PDT 2013
tst_accounts: ws zip: WS_out_20130314.tar.gz dat: area_20130314.dat count: 19732 db table rows: xx timestamp: Thu Mar 14 11:59:28 PDT 2013
End [test.sh] Script Run at Thu Mar 14 11:59:44 PDT 2013
Begin [test.sh] Script Run at Thu Mar 15 09:00:00 PDT 2013
tst_accounts: ws zip: WS_out_20130313.tar.gz dat: test_20130313.dat count: 63574 loaded: xx pre-merge: xx post-merge: xx timestamp: Thu Mar 14 09:30:42 PDT 2013
tst_accounts: ws zip: WS_out_20130313.tar.gz dat: s_20130313.dat count: 168217 loaded: xx pre-merge: xx post-merge: xx timestamp: Thu Mar 14 09:47:05 PDT 2013
tst_accounts: ws zip: WS_out_20130314.tar.gz dat: area_20130314.dat count: 19732 db table rows: xx timestamp: Thu Mar 14 11:59:28 PDT 2013
End [test.sh] Script Run at Thu Mar 15 14:00:00 PDT 2013 

i want the output as like below..
For every begin and end i need the count. count need to take the "count:" string followed by the number...

DATE          START     END     DURATION  # of RECORDS
14-Mar-2013   9:24:16   11:59:44   2:35:28     251523       =>63574+168217+19732
15-Mar-2013   9:00:00   14:00:00   4:00:00     251523      =>63574+168217+19732 

Thanks

What have you tried so far?

still i didn't get any idea..

A crude approach( I am assuming that the file format remains same ( no change of field positions etc).

Pls note that , I did not do the calculation of duration here ( you have to find out some way to do it in script).

awk 'BEGIN { print "DATE          START          END     DURATION  # of RECORDS" }
 /count/  { gsub(".*count:","",$0) ; b+=$1 }
 /Begin/ { s_t=$8"-"$7"-"$NF;s_ts=$9 ; next}
 /End/ {e_t=$8"-"$7"-"$NF;e_ts=$9; print s_t"   "s_ts"   "e_ts"    duration  "b;b=0}' file

Thank@panyam

Can you help me how to find the duratition...

---------- Post updated at 08:28 AM ---------- Previous update was at 07:59 AM ----------

Any help on this one

try the below:

Please note that: I am assuming the start and end time of the script run is on same day and then doing the calculation.

awk 'BEGIN { print "DATE          START          END     DURATION  # of RECORDS" }
function diff_bw_times(s_time , d_time) {
 split(s_time,ary, /:/); t_s=3600*ary[1] + 60*ary[2] + ary[3];
 split(d_time,arr, /:/); d_s=3600*arr[1] + 60*arr[2] + arr[3];
 diff=d_s - t_s; ho=int(diff/3600) ; mi=int((diff-ho*3600)/60);sec=int(diff-ho*3600-(mi*60)) ; printf("%s:%s:%s\t",ho,mi,sec);
 }
 /count/  { gsub(".*count:","",$0) ; b+=$1 }
 /Begin/ { s_t=$8"-"$7"-"$NF;s_ts=$9 ; next}
 /End/ {
 e_t=$8"-"$7"-"$NF;
 e_ts=$9;
 print s_t "\t" s_ts "\t"  e_ts "\t" diff_bw_times(s_ts , e_ts) "\t" b }' file 

Thanks lot, as per my requirement it's running same date.