uniq command
Remove or count repeated adjacent lines.
- Text processing
- Package coreutils
- 4 options · 4 examples
On this page
Syntax
uniq [options] [input [output]]Provided by the coreutils package. Run man uniq for the full manual.
Common options
| Option | What it does |
|---|---|
-c | Prefix each line with its count |
-d | Only print duplicated lines |
-u | Only print unique lines |
-i | Ignore case |
Examples
Remove duplicates (sort first)
sort list.txt | uniqCount occurrences
sort list.txt | uniq -cMost common lines first
sort access.log | uniq -c | sort -rn | headOnly lines that repeat
sort list.txt | uniq -d
No example matches. Check the options table or search the guides.
Tips
uniqonly compares neighbouring lines, so sort the input first.
