[wplug] converting HH:MM:SS to count of seconds

Alexandros Papadopoulos apapadop at alumni.cmu.edu
Mon Dec 20 09:07:00 EST 2004


Dear all

I have an ASCII file with lots (tens of thousands) of lines like these:
01.11.04%13:35:51%1%847%00:00:02%141                  % 2
01.11.04%13:36:33%5%841%00:00:27%2102319811           % 1
01.11.04%13:36:35%1%847%00:00:03%141                  % 2
01.11.04%13:37:16%1%841%00:00:11%2103645318           % 1
01.11.04%13:37:32%5%837%00:00:58%2102729811           %35

I'd like to convert the 5th field, as delimited by %'s (which is 
duration of a phone call) to a single number, designating seconds of 
duration.

Hence:
00:00:02 becomes 2
00:04:31 becomes 271  (0*60^2 + 4*60^1 + 31*60^0)
02:00:05 becomes 7205 (2*60^2 + 0*60^1 + 5*60^0)
and so on.

Can anyone suggest a way to accomplish this with standard UNIX tools? 
(bc, cut, perl, grep & friends)

Thanks

-A


More information about the wplug mailing list