UNIQ COMMAND:
Uniq command is helpful to remove or detect duplicate entries in a file.
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
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
No comments:
Post a Comment