Untitled Document
uniq Command

uniq - reports or filters out repeated lines in a file. When we concatenate or merge files , we will face the problem of duplicate enteries in new file . We have to sort removes them with -u option . UNIX / Linux has uniq command to handle these duplicate lines .

Example 1 - Basic Example

Run the following uniq command ,which simply fetches one copy of each line from user.txt file and writes it to standard output .

   uniq user.txt      
Since uniq requires a sorted file as input , the general procedure is to sort a file and pipe its output to uniq .

Example 2

The foloowing example produces same output as above , except that the output is saved in new file called user.uniq.txt . uniq , If provided with two file names as argument , uniq will read first file and writes its output to second .

   sort user.txt | uniq - user.uniq.txt    

Example 3 - Selecting Non Repeated Lines ( -u ) option

To detrmine the designation that occurs uniquely in emp.csv , run uniq command with -u option .

   uniq -u emp.csv  

Example 4 - Selecting duplicate lines ( -d ) option

The -d ( duplicate) option selects only one copy of the repeated lines .

  uniq -d emp.csv 

Example 5 - Counting Frequency of Occurence ( -c ) option

The -c ( count ) option displays the frequency of occurence of all lines , along with the lines .

  uniq -c emp.csv 
Untitled Document