Sponsored Content
Top Forums UNIX for Advanced & Expert Users Want to get average value for each hour Post 302941292 by Don Cragun on Tuesday 14th of April 2015 08:17:34 PM
Old 04-14-2015
Quote:
Originally Posted by Saravanan_0074
I have received hourly average for using below script, but i need daily average value.

Code:
awk -F'|' 'NR>2 {hour=" " substr($2,1,2); array[$1 hour] += $3 count[$1 hour]++ } END { for (a in array) {print a, array[a]/count[a] } } ' filec | sort 
03/02/2015 00 26.2439
03/02/2015 01 25.3431
03/02/2015 02 24.7481
03/02/2015 03 26.6714
03/02/2015 04 10.4339
03/02/2015 05 17.3723
03/02/2015 06 17.5681
03/02/2015 07 23.8506
03/02/2015 08 14.3764
03/02/2015 09 15.7681
03/02/2015 10 18.7348
03/02/2015 11 20.1648
03/02/2015 12 22.8531
03/02/2015 13 22.2181
03/02/2015 14 16.4239
03/02/2015 15 25.3914
03/02/2015 16 20.2731
03/02/2015 17 12.3039
03/02/2015 18 17.9764
03/02/2015 19 22.6573
03/02/2015 20 15.7089
03/02/2015 21 32.6081
03/02/2015 22 17.2506
03/02/2015 23 21.6848

As mjf already said, why gather each hour's data and calculate an average of each input line if you're trying to calculate a daily average.

But, in addition to that, there aren't any | characters in your input. So, with -F'|' in your code, there is nothing in $2 nor in $3 in your input. And, there is no header in this data, so, unless you want to skip data from the midnight hour and the 1am hour data in your daily averages, you don't want the NR>2. And, as has been said before, if you're going to use a single line scrunched up awk script, you MUST separate statements from each other with semicolons. And, since you data appears to be in month/day/year format instead of year/month/day, you need to modify your sort if the goal is to print the output in increasing date order when you run this code with data from December in one year and January in the next year...

Perhaps you wanted something more like:
Code:
awk '{array[$1]+=$3;count[$1]++}END{for(a in array){print a,array[a]/count[a]}}' filec|sort -k1.7,1.10 -k1.1,1.2 -k1.4,1.5

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

1 Hour less

set DAY=`date +%y%m%d` set H=`date +%H` set M=`date +%M` mailx -s "$H-Mydata" myemail@mail.com<mydata I am looking to set the current hour to have 1 hour less in the subject header: For example: let's say the system time is 8 I want to have "7-Mydata" not "8-Mydata" Can some1... (6 Replies)
Discussion started by: bobo
6 Replies

2. UNIX for Dummies Questions & Answers

an hour less in 24 hour system

My program: __________________________________ #!/bin/ksh DAY=`date +%y%m%d` H=`date +%H` M=`date +%M` day=`date +%m/%d/%y` let h=$H-1 echo DAY $DAY echo H $H echo M $M echo day $day echo h $h _____________________________________ My result: (3 Replies)
Discussion started by: bobo
3 Replies

3. Shell Programming and Scripting

help in hour grep

i have this script that checks for yesterday date and also specific hour in that ----------------------------------------------------------------- TZ=`date +%Z`+24 ;a=`date +%Y-%m-%d %k` cd logs count=0 for i in DBMaint.log do cat $i | grep $a >> file12.txt done... (0 Replies)
Discussion started by: ali560045
0 Replies

4. Shell Programming and Scripting

Counting average data per hour

Hi i have log like this : Actually i will process the data become Anybody can help me ? (6 Replies)
Discussion started by: justbow
6 Replies

5. What is on Your Mind?

Power Hour?

I had some free time at work today so I decided to get a little practice with my shell scripts (I'm pretty new to the whole UNIX thing). I'm sure I'm not the only college student here so maybe this code will come in handy for future weekends. #!/bin/sh if then echo "No playlist... (0 Replies)
Discussion started by: thedoobieman5
0 Replies

6. Shell Programming and Scripting

Getting the last hour from a log.

I have a log like this: Jan 26 13:59:41 server2 ntpdate: step time server 91.189.94.4 offset 0.065456 sec Jan 26 13:59:41 server2 ntpd: ntpd 4.2.4p8@1.1612-o Fri Aug 6 22:49:54 UTC 2010 (1) Jan 26 13:59:41 server2 ntpd: precision = 1.000 usec Jan 26 13:59:41 server2 ntpd: ntp_io: estimated max... (2 Replies)
Discussion started by: Jotne
2 Replies

7. UNIX for Dummies Questions & Answers

Load average spikes once an hour

Hi, I am getting a high load average, around 7, once an hour. It last for about 4 minutes and makes things fairly unusable for this time. How do I find out what is using this. Looking at top the only thing running at the time is md5sum. I have looked at the crontab and there is nothing... (10 Replies)
Discussion started by: sm9ai
10 Replies

8. Shell Programming and Scripting

How to convert 24 hour time to 12 hour timing?

Hi friends, I want to convert 24 hour timing to 12 hour please help me... my data file looks like this.. 13-Nov-2011 13:27:36 15.32044 72.68502 13-Nov-2011 12:08:31 15.31291 72.69807 16-Nov-2011 01:16:54 15.30844 72.74028 15-Nov-2011 20:09:25 15.35096 ... (13 Replies)
Discussion started by: nex_asp
13 Replies

9. Shell Programming and Scripting

How to get next hour?

Hi guys I want any script to get me next hour For example Nexthour.sh 2013022823 It get me result 2013030100 Thanks a lot , I'm using Solaris 10 (5 Replies)
Discussion started by: teefa
5 Replies

10. Shell Programming and Scripting

Average of multiple time-stamped data every half hour

Hi All, Thank you for reading through my post and helping me figure out how I would be able to perform this task. For example: I have a list of continuous output collected into a file in the format as seen below: Date...........Time........C....A......... B ==========================... (5 Replies)
Discussion started by: terrychen
5 Replies
WMEMMOVE(3)						     Linux Programmer's Manual						       WMEMMOVE(3)

NAME
wmemmove - copy an array of wide-characters SYNOPSIS
#include <wchar.h> wchar_t *wmemmove(wchar_t *dest, const wchar_t *src, size_t n); DESCRIPTION
The wmemmove() function is the wide-character equivalent of the memmove(3) function. It copies n wide characters from the array starting at src to the array starting at dest. The arrays may overlap. The programmer must ensure that there is room for at least n wide characters at dest. RETURN VALUE
wmemmove() returns dest. ATTRIBUTES
For an explanation of the terms used in this section, see attributes(7). +-----------+---------------+---------+ |Interface | Attribute | Value | +-----------+---------------+---------+ |wmemmove() | Thread safety | MT-Safe | +-----------+---------------+---------+ CONFORMING TO
POSIX.1-2001, POSIX.1-2008, C99. SEE ALSO
memmove(3), wmemcpy(3) COLOPHON
This page is part of release 4.15 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https://www.kernel.org/doc/man-pages/. GNU
2015-08-08 WMEMMOVE(3)
All times are GMT -4. The time now is 09:31 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy