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?

1
  • 1
    Just to make sure you are not reinventing the wheel: you are aware of opreport command, right? Nov 30, 2011 at 9:18

1 Answer 1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .