On Thu, Feb 28, 2002 at 02:01:19AM -0800, rocky g wrote:
> Hi,
> 
> I am writing a shell script which does billing on time
> basis and i need to add the following
> (Format hh:mm:s)
> 00:10:15 
> 00:05:8
> 
> how to add the time..
> 
> Pl. help me..
> 
---end quoted text---

     Correct me if I am wrong. From what I gather all that
you need is a method of adding multiple time  slices which
you want to input from a file or interactively.

     The easiest way would be to convert  all  to seconds,
add them all up and then convert back to hh:mm:ss.

     Assuming you have a input file with data  like:
     
     ....
     01:10:15
     00:05:08
     00:12:12
     ....
     
     Your script would be something like this:
     
     ----------------<snip>--------------------------
     #!/bin/sh
     TOTAL=0
     for i in `cat $1`; do
         HH=`echo $i | cut -b 1-2`; HH=$((HH*60*60))
         MM=`echo $i | cut -b 4-5`; MM=$((MM*60))
         SS=`echo $i | cut -b 7-8`
         TOTAL=$((TOTAL+HH+MM+SS))
     done
     echo -en "Total Duration (hh:mm:ss) = "
     echo $((TOTAL/3600)):$((TOTAL/60%60)):$((TOTAL%60)) 
     exit
     -----------------</snip>-----------------------
          
     You need to call this script with the datafile name.
     
HTH

Bish     

--     
:
####[ Linux One Stanza Tip (LOST) ]###########################

Sub : Julian dates                                   LOST #149

There is a need at times to  know how  many days  have  lapsed
since Jan 1 (Julian dates). The easiest way out is to  use the
cal program [ Try: cal -j 10 2001 ... and have a look !]

####<[EMAIL PROTECTED]>####################################
:

_______________________________________________
linux-india-help mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/linux-india-help

Reply via email to