Home > Archive > AWK > March 2006 > count distinct values
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
count distinct values
|
|
| patrick 2006-03-21, 7:55 am |
| Hello,
I have in a file
1, 100, 2, ...
3, 100, 2, ...
5, 200, 2, ...
8, 100, 2, ...
I'm able to display distinct values from second column with awk and an
array.
I get :
100
200
But is there a way to count them ?
like
100 : 3
200 : 1
Thanks in advance.
| |
|
| "patrick" <patrick.beltranne@caramail.com> ha scritto nel messaggio
news:1142936224.485883.215190@j33g2000cwa.googlegroups.com...
> Hello,
>
> I have in a file
>
> 1, 100, 2, ...
> 3, 100, 2, ...
> 5, 200, 2, ...
> 8, 100, 2, ...
>
> I'm able to display distinct values from second column with awk and an
> array.
> I get :
> 100
> 200
>
> But is there a way to count them ?
> like
> 100 : 3
> 200 : 1
From the comp.unix.shell group archive:
http://tinyurl.com/pof4x
Regards,
Dimitre
| |
| patrick 2006-03-21, 7:55 am |
|
DR a =E9crit :
> From the comp.unix.shell group archive:
>
> http://tinyurl.com/pof4x
>
>
> Regards,
> Dimitre
Thanks !
It works fine...
although I don't understand very well the logic before the END :
{a[$2]++}
| |
| Janis Papanagnou 2006-03-21, 9:57 pm |
| patrick wrote:
> DR a écrit :
>
>
> Thanks !
> It works fine...
> although I don't understand very well the logic before the END :
> {a[$2]++}
For every input line increment the contents of the array element that
is indexed by the second input field.
The array elements are initially undefined, and they take the value 0
when they are accessed to be incremented.
Janis
|
|
|
|
|