utility

uniq

Collapse consecutive duplicate lines; -c counts runs. Sort first for global identical-line counts.

Formal Syntax & Structure

bash syntaxbash
uniq [-c] [INPUT [OUTPUT]]

Parameters & Attributes

NameTypeDescription
INPUTpathInput path, otherwise stdin.
-coptionPrefix each run with its count.

Return Value

exit status

Exit status 0 on success; nonzero indicates failure or a command-specific condition. See description and example.

Working Example

Example Snippetbash
printf '%s\n' red blue red green blue red | LC_ALL=C sort | uniq -c
Bash Reference