[question] hard exercise, help needed

Hello guys.

Well, on this exercise i need the average "chargeAmount" per hour (for each hour).

with this code :

cat getusagesummarywrongmatch | grep -iv MOU2GRTObject | cut -d'|' -f4,14 | grep -i  chargeamount | cut -d' ' -f2 

i got the fields that i need, then with the awk comand i took the 1st and 4th fields separated by ":" .
But i couldnt get the total and average of chargeamount for each hour.

Hope you guys can help me again :slight_smile:

thanks in advance

Let's hope this is not homework.

add the following "pipe" to the end your existing line of code

| awk -F':' '{cnt[$1]++; arr[$1]+=$NF  } 
  END {for (i in arr) { printf "%d %.2f\n",i, arr/cnt) }'

cat getusagesummarywrongmatch | grep -iv MOU2GRTObject | cut -d'|' -f4,14 | grep -i chargeamount | cut -d' ' -f2 | awk
-F':' '{cnt[$1]++} {arr[$1]+=$4} END {for(i in arr) printf("Hour: %d Average: %.2f\n",i,arr[i]/cnt[i])}' | sort;

thanks a lot :slight_smile: