Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
Just to make sure you are not reinventing the wheel: you are aware of opreport command, right? – Janne Pikkarainen Nov 30 '11 at 9:18

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
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.