Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

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
  1. How to remove duplicated lines in a file
  2. Count the number of matching lines from grep
  3. How to count the number of line in a file
  4. Count the total number of objects in the collection in MongoDB
  5. Count the total number of logged in user

Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>