uniq Command Examples

Output the unique lines from a input or file. Since it does not detect repeated lines unless they are adjacent, we need to sort them first. More information: https://www.gnu.org/software/coreutils/manual/html_node/uniq-invocation.html.

sort {{path/to/file}} | uniq

sort {{path/to/file}} | uniq {{[-u|--unique]}}

sort {{path/to/file}} | uniq {{[-d|--repeated]}}

sort {{path/to/file}} | uniq {{[-c|--count]}}

sort {{path/to/file}} | uniq {{[-c|--count]}} | sort {{[-nr|--numeric-sort --reverse]}}