Hi Friends,
In continuation to my earlier post
I am extending my problem as follows.
Input:
Column1 Column2
MAS 1
MAS 4
MAS 7
Delhi 10
Delhi 13
Delhi 16
Delhi 20
Mumbai 22
Mumbai 67
..................................
.................................. so on. In my file I have 10000 rows.
I need to get the average of col2 for each unique key in col1 along with count of unique keys. By this way I should get the following output
MAS, 3, 4.0
Delhi,4, 14.75
Mumbai,2, 44.5
......... and so on.,
I need an automated script for this as I have 1000's of entries in Column 1 because it is almost impossible to put each key in script itself.
So I request you to please modify the below script to meet to my requirement.
awk '/^MAS/ || /^Delhi/ { ++n; sum += $3 } END { print sum / n }' Input_file
Thanks in advance..