uniq
uniq linux command cheatsheet by Thamizhiniyan C S
Introduction
Unique command filters the output (from either a file or stdin) to remove any duplicates.
Syntax
uniq [OPTION]... [INPUT [OUTPUT]]
Important Flags
-c
To count the occurrences of every line in file or stdin
-d
Will only print the lines that are repeated, not the one which are unique
-u
Will only print lines that are already uniq
-i
Ignores case(Default is case-sensitive)
Examples
uniq
Remove the consecutive repetitions of any line
uniq -c | cut -c 7-
Count the occurrences of consecutive identical lines in the input, then cut out the first six characters (presumably to remove the counts added by uniq -c
), leaving only the original content of the lines
uniq -c -i | cut -c 7-
Count the occurrences of consecutive identical lines while ignoring case differences and then remove the count information, leaving only the original content of the lines
uniq -u
Print only the lines that occur exactly once in the input, discarding any duplicate lines.
Last updated
Was this helpful?