Skip to content

How to count the number of duplicated lines in a file

How to count the number of duplicated lines in a file

Answer:

Assume you have a file "test.txt"

a
b
b
c
c
c

You want to count the number of distinct rows, here is the command

# sort test.txt | uniq -c

1 a
2 b
3 c
Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  1. How to remove duplicated lines in a file
  2. Count the number of matching lines from grep
  3. Find duplicated records in MySQL
  4. Join lines on a common field
  5. Remove empty lines in a file

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*