RE: [SLUG] need shell script routine

From: Rock (mrock@stewartsigns.com)
Date: Fri Feb 06 2004 - 14:45:23 EST


Eban, Thank you for the assistance.

Michael

-----Original Message-----
From: slug@nks.net [mailto:slug@nks.net] On Behalf Of Eben King
Sent: Friday, February 06, 2004 1:52 PM
To: slug@nks.net
Subject: Re: [SLUG] need shell script routine

On Fri, 6 Feb 2004, Rock wrote:

> I need a shell script routine that I can include in my program that
adds
> time in the format 00:00:00 hours:minutes:seconds for as many as 4
> consecutive records on many different occasions in a very large text
> file.

What do you do if it adds to more than one day? Assuming a form of "1d
23:59:59". I suppose you could do something like

#! /bin/pdksh
typeset -Z2 TOTAL_SECONDS=0 TOTAL_MINUTES=0 TOTAL_HOURS=0
TOTAL_DAYS=0

for component_time in 1 2 3 4 ; do
 TOTAL_SECONDS=$((TOTAL_SECONDS + $(<extract seconds field>) ))
 TOTAL_MINUTES=$((TOTAL_MINUTES + $(<extract minutes field>) ))
 TOTAL_HOURS=$((TOTAL_HOURS + $(<extract hours field>) ))
 <that's all folks> && break
done

while [[ $TOTAL_SECONDS -ge 60 ]] ; do
 TOTAL_MINUTES=$((TOTAL_MINUTES + 1))
done

while [[ $TOTAL_MINUTES -ge 60 ]] ; do
 TOTAL_HOURS=$((TOTAL_HOURS + 1))
done

while [[ $TOTAL_HOURS -ge 24 ]] ; do
 TOTAL_DAYS=$((TOTAL_DAYS + 1))
done

prefix=
[[ $TOTAL_DAYS -gt 0 ]] && prefix="$TOTAL_DAYSd"

echo "$prefix TOTAL_HOURS:TOTAL_MINUTES:TOTAL_SECONDS"
exit 0

I'm sure this can be done in bash, but I didn't know how to do "typeset
-Z2"
in bash. This is untested; caveat lector.

-- 
-eben    ebQenW1@EtaRmpTabYayU.rIr.OcoPm    home.tampabay.rr.com/hactar

Hi! I'm a .sig virus! Copy me to your .sig!

----------------------------------------------------------------------- This list is provided as an unmoderated internet service by Networked Knowledge Systems (NKS). Views and opinions expressed in messages posted are those of the author and do not necessarily reflect the official policy or position of NKS or any of its employees.

----------------------------------------------------------------------- This list is provided as an unmoderated internet service by Networked Knowledge Systems (NKS). Views and opinions expressed in messages posted are those of the author and do not necessarily reflect the official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 17:32:03 EDT