Counting time

I have been wrestling with a ksh module to calculate a series of elapes times in the format hh:mm:ss. I have use the 'cut' command to extract the seconds and minutes and added the results together and then divided by 60 to yield a result, then added the result to the next field, but this seems to be a rather primative way of handling the situation. Are there any suggestions that may provide a better way?

Thanks in advance

Hey black69star,
Check out the "timex" command. I don't know the structure of your script, but this may help you. Basically, you just run your command like normal but type timex infront of it. It then returns several bits of info that you can chop up, etc to get the time. This may or may not work for you.
Good Luck,
TioTony

I'm not sure what you're trying to do exactly. But if you have a string like "18:30:10" and you want to convert it to seconds after midnight, try:

#! /usr/bin/ksh
hms="18:30:10"
h=${hms%%:*}
s=${hms##*:}
temp=${hms%:*}
m=${temp#*:}
((secs=3600*h + 60*m +s))
echo $hms $h $m $s $secs
exit 0

By using only shell built-ins like this you can run must faster than if you invoke external processes like "cut".

Also, this thread may be of some help.