Thursday, March 27, 2014

                      UNIQ COMMAND:

     Uniq command is helpful to remove or detect duplicate entries in a file.

1.Basic Usage:

                                $ uniq [-options]

                                $ uniq test 
                                  aa 
                                  bb 
                                  xx

when uniq command is run without any option, it removes duplicate lines and displays unique lines.


2. Count Number of Occurrences using -c option:

                              $ uniq -c test
                                
                          2 aa
                          3 bb
                          1 xx
This Option Is To Count Occurence Of Lines In File.


 3. Print only Duplicate Lines using -d option:

          
                          
                     $ uniq -d test
                                  
                                   aa      
                                   bb

 The above example displayed all the duplicate lines, but only once. But, this -D option will print all duplicate lines in file. For example, line “aa” was there twice in the test file, so the following uniq command displayed the line “aa” twice in this output.
                         $ uniq -D test
                              aa 
                              aa
                              bb 
                              bb 
                              bb

4. Print only Unique Lines using -u option

This option is to print only unique lines in file. 
          

                $ uniq -u test
                       xx

 

5.Ignore differences in case when comparing:

                    $ uniq -i test

6.--help --display this help and exit


7.--version --output version information and exit.

The Other Options Are:

  c : Count of occurrence of each line.

  d : Prints only duplicate lines.

  D : Print all duplicate lines.

  f : Avoid comparing first N fields.

  i : Ignore case when comparing.

  s : Avoid comparing first N characters.

  u : Prints only unique lines.

  w : Compare no more than N characters in lines.

             

No comments:

Post a Comment