count number of rows based on other column values

Could anybody help with this?
I have input below .....

david,39
david,39
emelie,40
clarissa,22
bob,42
bob,42
tim,32
bob,39
david,38
emelie,47

what i want to do is count how many names there are with different ages, so output would be like this ....

david,2
emelie,2
clarissa,1
bob,2
tim,1

so there are three david's, but two of them are the same age so i would want it to come up with ...

david,male,2

If anybody could point me in the right direction it would be much appreciated :slight_smile:

Cheers

Awk seems the logical tool:

awk   '
        {
                seen[$1] = 1;
        }
        END {
                for( s in seen )
                        print( s );
        }
' list-flie

You'll have to add a table that maps names to sex, or supply that info in the list (e.g. david,male,29).

How about something like this:

$ sort -u infile | cut -d, -f1 | uniq -c
      2 bob
      1 clarissa
      2 david
      2 emelie
      1 tim
awk -F , '! a[$1 FS $2] {b[$1]++;a[$1 FS $2]++}END {for (i in b) print i","b}' infile