Text and processing
The uniq command
Removes consecutive repeated lines and, with -c, counts them.
Syntax
uniq [-c] [archivo]Most useful options
-cPrefixes each line with its repeat count-dShows only the repeated ones-uShows only the ones appearing onceCopy-ready examples
$ printf 'a\na\nb\n' | uniqRemoves adjacent repeats$ printf 'a\na\nb\n' | uniq -cCounts repeats$ printf 'b\na\nb\n' | sort | uniq -cCounts everything togetherYou can try them in the browser terminal: it does not touch your computer.
Typical mistakes
- It only groups adjacent repeats: sort first.
FAQ
Why does it not remove all duplicates?
Because uniq only looks at adjacent lines: run sort first.
Learn to actually use it
The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.
Start the free course