Results 1 to 3 of 3

Thread: Count average per minute using Linux / Unix shell scripts

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    10
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default Count average per minute using Linux / Unix shell scripts

    i am doing performance analysis, so i have to do some calculation from log file. i want to count average value per minute from log file.
    my log file is like this:
    Code:
    22:47:30.751 3
    22:47:30.754 2
    22:47:30.776 1
    22:47:31.756 8
    22:47:31.752 4
    22:47:32.752 9
    22:47:32.755 6
    22:47:32.751 3
    22:47:33.898 2
    22:47:33.751 10
    i can calculate column 2 average value from average of all that values, my problem is i need to calculate average value per minute from this log.
    so the output will be like this:
    Code:
    22:47:30 3  # (3+2+1)/3
    22:47:31 2
    22:47:32 6
    22:47:33 6
    i can only calculate the average of all these values but i am having a problem to calculate it per minute value.
    need help, thank you.

  2. #2
    Senior Member
    Join Date
    Aug 2011
    Posts
    447
    Thanks
    0
    Thanked 61 Times in 57 Posts
    Rep Power
    10

    Default

    hi,

    Code:
    $ cat $yourFile
    22:47:30.751 3
    22:47:30.754 2
    22:47:30.776 1
    22:47:31.756 8
    22:47:31.752 4
    22:47:32.752 9
    22:47:32.755 6
    22:47:32.751 3
    22:47:33.898 2
    22:47:33.751 10
    
    $ awk '{
       sub(/\..*/,"",$1)
       ar[$1]+=$2
       nb[$1]++
    }
    END{
       for(i in ar)print i" -> "ar[i]"/"nb[i]" - "ar[i]/nb[i]
    }' $yourFile
    22:47:33 -> 12/2 - 6
    22:47:30 -> 6/3 - 2
    22:47:31 -> 12/2 - 6
    22:47:32 -> 18/3 - 6
    A problem clearly stated is a problem half solved.

  3. The Following User Says Thank You to Watael For This Useful Post:

    initial (21st January 2013)

  4. #3
    Junior Member
    Join Date
    Sep 2012
    Posts
    10
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    wow, thanks for the script...i've created script for this work but so complicated (combination of sed and awk command) unlike your script. really helpful!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Unix / Linux: Perl count null word in Excel Spreadsheet
    By aish in forum Coding in General
    Replies: 2
    Last Post: 16th March 2012, 03:41 PM
  2. [Solved] Daily Linux server load average logging shell script
    By raleigh in forum Shell scripting
    Replies: 3
    Last Post: 8th November 2011, 07:20 PM
  3. SSH - Passing Unix login passwords through shell scripts
    By arulkumarr in forum Shell scripting
    Replies: 13
    Last Post: 3rd August 2010, 12:41 PM
  4. Replies: 5
    Last Post: 12th July 2009, 02:05 AM
  5. How to Count executable (x) files in Linux / UNIX?
    By eawedat in forum Shell scripting
    Replies: 4
    Last Post: 5th June 2009, 03:53 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •