Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract valors and time calculation

Status
Not open for further replies.

Yarka

Technical User
Jan 14, 2007
192
0
0
ES
hi,
I've a file as:
....
12 BC CA x xl 23:00:01,234 LAM
18 CA BC xa axj 23:30:12,333 KIL
4 VD GF ll pp 1:06:15,325 LOPP
55 III OP ghj poi 2:06:52,001 PO
.....

I need to obtain for each LAM of my file, the time passed between for LAM and 2 lines down. In this exemple, I want to have the time calculated with operation 1:06:15,325 - 23:00:01,234.
Can anybody help me??

Thanks.
 
Try...
Code:
awk '/LAM/{ split($6,a,/[:,]/)
            x = a[1]*3600 + a[2]*60 + a[3] "." a[4]
            getline
            getline
            split($6, a, /[:,]/)
            y = a[1]*3600 + a[2]*60 + a[3] "." a[4]
            z =  y - x + (x>y?86400:0)
            printf "%02d:%02d:%02.3f\n", z/3600, (z%3600)/60, z%60
         }' file1
Result...
Code:
02:06:14.091
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top