It is because the ++ in count[subscript]++ is a post-increment operation. That expression returns the value it had before the value is incremented and then increments the variable to the new value. To have it return the new value (instead of the old value), you would use the pre-increment operation ++count[subscript].
This User Gave Thanks to Don Cragun For This Post:
I have received hourly average for using below script, but i need daily average value.
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...
Don,
I interpreted the data Saravanan_0074 included in his/her last post to be the output, not the input, of running the awk command (in which case you would need-F'|'and NR>2). The avg of 26.2439 (should be 26.24) for hour 00 appears to match the input in the original post although there appears to not be enough input data to confirm the hours beyond 00 in the output.
Don,
I interpreted the data Saravanan_0074 included in his/her last post to be the output, not the input, of running the awk command (in which case you would need-F'|'and NR>2). The avg of 26.2439 (should be 26.24) for hour 00 appears to match the input in the original post although there appears to not be enough input data to confirm the hours beyond 00 in the output.
You are correct re: the sort of the date.
You may be correct. If that is the case, the only thing wrong with the Saravanan_0074's script was the missing semicolon (like the problem you had in post #2 in this script). But, it clearly is not going to provide a daily average; only hourly averages.
But, the stated goal in post #10 is to get the daily average, and the script in that post does NOT do that. And, it isn't clear which average is desired. Is the desire to get the arithmetic mean of the hourly arithmetic means? (That is what the script I suggested would provided if the data shown in post #10 was fed into it as input.) Is the desire to get the arithmetic mean of the individual data for each day? Or, is some other average desired???
Is there ever input for more than one day in the input file?
Are there always the same number of sample points for each day (and the same number of sample points each day for each hour)? What happens on days when there is a shift to or from daylight savings time?
Is the sort in the pipeline intended to sort average day values into date order? Or, is it intended to sort average hourly values for a single date into hour order? If daily averages and hourly averages are both supposed to be in the output, what is the sort order supposed to be? What output format is wanted for the daily average values?
Sometimes I get tired of trying to guess what requirements we are trying to meet.
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)
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)
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)
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)
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)
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)
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)
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)
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)