repetition calculation

 
cat mylist
 
First_NAME   Gender
Mike             M
Sara             F  
Raya           M
Sara           F
Fibi             F
Mike            M
Mike             M
Micheal        M

can someone please help me to get a script to cacluate the number of repetions for each (First name )sorted by highest reptetions to lowest so the output would something like

 
./myscript
 
Mike 3       
Sara  2  
Raya  1
Fibi  1
Micheal  1

Many Thaanks

Lot of pipes:

sed -n '2,$p' mylist | awk '{print $1}' | sort | uniq -c | awk '{print $2,$1}' | sort -nrk2

Perl.

perl -ane '($.==1)&& next; $x{$F[0]}++; END{for(keys %x){print "$_ $x{$_}\n"}}' mylist | sort -nrk2
1 Like

did u try search in this forum ?
there is lot of questions similar to your post.

---------- Post updated at 12:31 PM ---------- Previous update was at 12:27 PM ----------

 
$ nawk 'NR>1{a[$1" "$2]++;next}END{for(i in a){split(i,b," ");print b[1],a}}' input.txt | sort -nrk2
Mike 3
Sara 2
Raya 1
Micheal 1
Fibi 1

1 Like
# awk '!/NAME/{a[$1]++};END{for(i in a)print i,a}' mylist|sort -nrk2
Mike 3
Sara 2
Raya 1
Micheal 1
Fibi 1
1 Like