Friday, August 9, 2013

Searching Duplicate Lines from File @linux

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

Some are below example .
i have created one file here and add some lines there .

$ cat test
aa
aa
bb
bb
bb

xx

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

$ uniq test
aa
bb

xx
Count Number of Occurrences using -c option

$ uniq -c test
      2 aa
      3 bb
      1 xx


Print only Duplicate Lines using -d option

This option is to print only duplicate repeated lines in file. As you see below, this didn’t display the line “xx”, as it is not duplicate in the test file.

$ uniq -d test
aa
bb

Print only Unique Lines using -u option

This option is to print only unique lines in file.

$ uniq -u test
xx

No comments:

Post a Comment