Linux uniq

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

Linux uniq

With the help of uniq command you can form a sorted list in which every word will occur only once.

Syntax:

  1. command <fileName> | uniq  

Example:

  1. sort dupli.txt | uniq  

Linux Uniq Filters1

Look at the above snapshot, words which are repeating, repeats only once with the 'uniq' command.


uniq -c

You can count the number of occurences of a word with 'uniq -c' command.

Syntax:

  1. command <fileName> | uniq -c  

Example:

  1. sort dupli.txt | uniq -c  

Linux Uniq Filters2

Look at the above snapshot, command "sort dupli.txt | uniq -c" counts the number of times a word is repeating.