sort

What is the easiest way to count duplicate lines?

example:
aaa
b
b
b
b
b

Output:
aaa 1
b 5

Sorry, maybe someone already ask for it,
but I can not find.

There can be some very simple solution to this problem, BUT using awk, this is how we can achieve this

$ cat file.txt
aaa
b
b
c
c
b
b

I am adding a second field to all lines of file.txt as "1", then using associative array.

$ awk '{print $0,1}' file.txt | awk '{arr[$1]+=$2} END {for (i in arr) {print i,arr}}'
aaa 1
b 4
c 2

//Jadu

A quick search of this site would have turned up lots of threads on related issues.

awk '{count[$1]++}END{for(j in count) print j,count[j]}'