The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




Thread: sort
View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #3 (permalink)  
Old 01-27-2008
shamrock shamrock is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2007
Location: USA
Posts: 750
Quote:
Originally Posted by mirusnet View Post
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.
A quick search of this site would have turned up lots of threads on related issues.

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