uniq Linux Commands
What is Linux uniq Command?
Explanation
uniq COMMAND:uniq cmd is used to remove the duplicate records in directories by comparing the directories. This command can also be used to get the unique words or characters in a sorted file.
SYNTAX :
uniq [OPTION]... [INPUT [OUTPUT]]
OPTIONS:
-c, --count |
prefix lines by the number of occurrences. |
-d, --repeated |
only print duplicate lines. |
-D |
delimit-method={none(default),prepend,separate} Delimiting is done with blank lines. |
-f, --skip-fields=N |
avoid comparing the first N fields |
-i, --ignore-case |
ignore differences in case when comparing |
-s, --skip-chars=N |
avoid comparing the first N characters |
-u, --unique |
only print unique lines |
--version |
output version information and exit |
EXAMPLE:
-
uniq test.txt
Output:
a
b
c
f
d
In the above example, uniq command displays the unique characters in the file test.txt.
-
uniq -c test.txt
Output:
1 a
1 b
1 c
1 f
1 d
In the above example, uniq command displays lines with the number of occurrences in the file test.txt.