text pattern count statistic

Hi all

is it possible to have a text pattern count statistic by using simple script instead count it one by one ?

apple
apple
boy
boy
boy
boy
cat
cat
cat
cat
cat
dog....
...

apple = 3
boy = 4
cat = 5
dog .....

If there is only one word per line, then this should work:

awk '{a[$0]++}END{for (i in a){print i" = "a}}' file

Or shorter:

sort file | uniq -c
1 Like

-bash-3.2# sort 5.txt | uniq -c
2 apple
4 boy
5 cat

pludi thanks.