0

I have program generating reports on a regular basis.
These reports are follow a simple and consistent format (specifically, these are "OProfile profiling reports).
Each line's format is:

  • Unique_name,number

I wish to run over all the reports I have and calculate (say) and average for each unique_name.

How could this be done?

Trevor
  • 193
  • 1
  • 4

1 Answers1

1

Assuming that all the reports located in a directory and have the .txt extension. Try this:

$ cat *.txt | gawk -F, 'NF==2 { sum[$1] += $2; N[$1]++ } \
    END { for (name in sum) { \
        printf "%s %f\n", name, sum[name] / N[name]; } }' | sort -k2 -n
quanta
  • 51,413
  • 19
  • 159
  • 217