Output formatting .

below is a CPU utilization Log for ABC server.
However for every 15 minutes it generates 3 CPU values(with interval of 2 sec).

Host  CPU CPUtotal CPU% time
ABC 101.1 2 50.55 14 : 15
ABC 100.5 2 50.25 14 : 15
ABC 100.2 2 50.1 14 : 15
ABC 100.9 2 50.45 14 : 30
ABC 100.5 2 50.25 14 : 30
ABC 100.4 2 50.2 14 : 30
ABC 101.0 2 50.5 14 : 45
ABC 100.9 2 50.45 14 : 45
ABC 100.4 2 50.2 14 : 45
ABC 101.1 2 50.55 15 : 00
ABC 100.7 2 50.35 15 : 00
ABC 100.5 2 50.25 15 : 00
ABC 101.1 2 50.55 15 : 15
ABC 101.0 2 50.5 15 : 15
ABC 100.5 2 50.25 15 : 15
ABC 101.1 2 50.55 15 : 30
ABC 100.9 2 50.45 15 : 30
ABC 100.4 2 50.2 15 : 30
ABC 102.2 2 51.1 15 : 45
ABC 101.4 2 50.7 15 : 45
ABC 100.7 2 50.35 15 : 45

How would i list average value of cpu % at after every 15 minuates.
Say.

ABC 101.1 2 50 14 : 15
ABC 101.1 2 50 15 : 00
ABC 101.1 2 50 15 : 15
ABC 100.4 2 50 15 : 30
ABC 102.2 2 50 15 : 45

Please suggest .

---------- Post updated at 06:43 AM ---------- Previous update was at 05:33 AM ----------

I can generate the output like this but this is not what i expect.

$ awk '{sum+=$4; ++n; print $4 }; END { print "------"; print "Tot="sum"("n")";print "Avg="sum"/"n"="sum/n} ' cpu.txt
50.55
50.25
50.1
50.45
50.25
50.2
50.5
50.45
50.2
50.55
50.35
50.25
50.55
50.5
50.25
50.55
50.45
50.2
51.1
50.7
50.35
------
Tot=1058.75(21)
Avg=1058.75/21=50.4167

but i m expecting output in following format.

ABC 101.1 2 50 14 : 15
ABC 101.1 2 50 15 : 00
ABC 101.1 2 50 15 : 15
ABC 100.4 2 50 15 : 30
ABC 102.2 2 50 15 : 45                      

With reference to your desired output -

ABC 101.1 2 50 14 : 15
ABC 101.1 2 50 15 : 00
ABC 101.1 2 50 15 : 15
ABC 100.4 2 50 15 : 30
ABC 102.2 2 50 15 : 45

(a) Why do you not want 14:30 and 14:45 in your output ?
(b) Is 50 the average value ? What is it the average of ?
(c) Why do all the lines have 50 as the average ?

tyler_durden

1)Why do you not want 14:30 and 14:45 in your output ?
Ans:For every 15 min interval there are 3 entries generated therefore i need only one entry specifying average of cpu %.
2)Is 50 the average value ? What is it the average of ?
No its not it was just an example it may be 49.54 (i didn't use calc).
3)Why do all the lines have 50 as the average ?
I guess above says it all.

I will make it more clear to avoid any further confusion.It seems to be very difficult for me to think of any logic.

ok i will make it more clear.

I would like to take above file as input .
Notice that for every 15 minuate interval there are some entries generated.
for example : for 14:15 there are 3 entries .
for 14:30 there are 2 entries.

I would like to get average of cpu% considering time.
say.

awk 'NR>1{perc+=$4} NR>1 && (NR-1)%3==0{avg[count++] = $1" "$2" "$3" "perc/3" "$5$6$7; perc=0} END{for (i=0;i<count;i++) print avg}' file

Add another var to average CPU as well

@pinga
Didn't that command worked which i gave ?

Not on console now.Will check and let you know .
Thanks for the help.