Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
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
add comment

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

Your Answer

 
discard

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.