Calculate difference in timestamps based on unique column value

Hi Friends,
Require a quick help to write the difference between 2 timestamps based on a unique column value:
Input file:

08/23/2012 12:36:09,JOB_5340,08/23/2012 12:36:14,JOB_5340
08/23/2012 12:36:22,JOB_5350,08/23/2012 12:36:26,JOB_5350
08/23/2012 13:08:51,JOB_5360,08/23/2012 13:08:58,JOB_5360

Output Required:

08/23/2012 12:36:14,08/23/2012 12:36:09,00:00:05,JOB_5340
08/23/2012 12:36:26,08/23/2012 12:36:22,00:00:04,JOB_5350
08/23/2012 13:08:51,08/23/2012 13:08:58,00:00:07,JOB_5360

I'm using ksh on AIX machine, and the ksh version is Version M-11/16/88f
Many Thanks
NK

The ksh does not have date arithmetic, but you can decompose the lines, fields to the integers and write some calendar subroutines to do the subtraction. I would use sed to turn the various numbers into variable settings:

$( echo $f |sed -n '
  s/^\(..\)\/\(..\)\/\(....\) \(..\):\(..\)/yy=\3 mo=\1 dy=\2 hh=\4 mi=\5 ss=\6/p'
 ' )

If you are inclined to reduce them to something like integer UNIX Zulu time, I have found it best to shift the epoch slightly (March 1, 1968) so the first days, month days for March through January, February is whatever is left over. The new epoch has 365x4+1 day quad-years from 3/1/1900 to 2/28/2100 as 2000 was a leap year century.

DGPickett,

Thanks much for your response.

Can you please send me a script that can be used to integrate into my current scripts.

Many Thanks,
Nandha

From googling for shell date arithmetic, I think you can find actual libraries of that stuff. I wrote mine in C for mass production, and posted it here somewhere: tm2tm.c "date" difference between FreeBSD & Linux

AIX has ksh93, which has an almost hidden ability to parse and present date/time that has not made it into bash yet, as far as I can see: Korn Shell 93 Date/Time String Manipulation and Arithmetic | PDF | Software Development | Computer Programming It's native to AIX: IBM Documentation

$ echo 08/23/2012 12:36:40 12:36:45| tr " " ":" | cut -d":" -f2- | awk -F":" '{tm=($1*3600)+($2*60)+$3; tm2=($4*3600)+($5*60)+$6; tmd=tm2-tm; print tm,tm2,tmd}'
45400 45405 5

I just used a part of your line, and then had awk do some simple math. Now it assumes the times are on the same day. But, this may give you an idea of how to proceed.