The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to average in awk saint2006 Shell Programming and Scripting 4 06-04-2008 08:29 AM
Average completion time calculation? Seawall UNIX for Dummies Questions & Answers 5 05-20-2008 03:13 AM
average transaction time nhatch Shell Programming and Scripting 2 05-02-2007 05:11 AM
average value su_in99 UNIX for Dummies Questions & Answers 2 03-10-2007 09:41 AM
How to find no of occurances Finding average time? redlotus72 UNIX Desktop for Dummies Questions & Answers 1 02-21-2005 11:22 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-16-2008
Registered User
 

Join Date: Jan 2008
Posts: 1
Post Average Time

Hi Guys,
I am using a command

$ runprt_req PPGUS_ROYXN1102
Output:
**************** Start Date and Time End Date and Time***
PPGUS_ROYXN1102 01/15/2008 02:20:08 01/15/2008 04:54:50
PPGUS_ROYXN1102 01/12/2008 02:03:57 01/12/2008 04:22:10
PPGUS_ROYXN1102 01/11/2008 02:07:55 01/11/2008 04:28:54
PPGUS_ROYXN1102 01/10/2008 03:13:57 01/10/2008 04:52:24

I need to find the average time between Start and End Time
Ex: 02:20:08 - 04:54:50 So the average time is 02:34:02

Similarly i need the average time for the all the columns
Ex:
Start Time End Time Average Time
02:30 02:40 00:10
03:30 03:30 00:00
...........
I have a very big output, so its difficult to find the average time easily.
It will be helpfull for me, if i get a command or a script.
I tried using awk command, but i not much familiar with unix, so i didnt get any output except Syntax Error
Thanks in Advance.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 01-16-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,448
Code:
#!/bin/sh
awk 'NR>1{
        n=split($3,starttime,":")
        m=split($NF,endtime,":")
        s_hr=starttime[1]
        s_min=starttime[2]
        s_ss=starttime[3]
        e_hr=endtime[1]
        e_min=endtime[2]
        e_ss=endtime[3]
        stime = (s_hr * 60 * 60) + (s_min * 60) + s_ss
        etime = (e_hr * 60 * 60) + (e_min * 60) + e_ss
        timedifference = etime - stime
        print timedifference " secs"
        # I leave to you to calculate back the average time in hr:min:sec
        # hint: take timedifference divide by 3600 to get hr. convert the remainder to min and secs

}
' "file"
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:19 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0