Calculate the Time stamp difference

hi,

I have a log file which gives time stamps hh:mm:ss.sssss format in which
hh- hours , mm -minutes ss.sssss - seconds.microseconds

I need to calculate the time diff between sent time stamp and received time stamp ....

could any one please help me..

i am tryin to write a script but it is becoming very lengthy...

Thanks,
Firestar

Please post:

  1. sample of your logfile
  2. sample of expected ouput (evt. explain the logic you want to involve)
  3. result of the command 'date --version'

Here an example:

# cat time.sh
TIME()
{
   integer seconds
   integer h1 m1 s1 time1
   integer h2 m2 s2 time2

   echo "$1" | IFS=':' read h1 m1 s1
   echo "$2" | IFS=':' read h2 m2 s2
   (( time1 = h1*3600  + m1*60 +s1 ))
   (( time2 = h2*3600  + m2*60 +s2 ))

   (( seconds = time1 - time2 ))
   (( seconds < 0 )) && (( seconds = -seconds ))

   (( h1 = seconds / 3600 ))
   (( m1 = seconds / 60 % 60 ))
   (( s1 = seconds % 60 ))
   printf "%02d:%02d:%02d\n" $h1 $m1 $s1
}

# . time.sh; TIME 01:17:50 02:47:50
01:30:00

Cheers :wink: