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?

link|improve this question

25% accept rate
1  
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
feedback

1 Answer

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
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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