commands
uniq — collapse adjacent repeated lines
Compare adjacent lines, not all lines. -c counts groups, -d prints repeated groups, -u prints groups occurring once. Sort first for global grouping if order may change. Example assumes a fresh text-streams lab fixture.
Formal Syntax & Structure
linux syntaxlinux
uniq [OPTION]... [INPUT [OUTPUT]]Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| -c | option | Count groups |
| -d | option | Repeated groups |
| -u | option | Nonrepeated groups |
| INPUT | operand | Input file |
| OUTPUT | operand | Distinct output file |
Return Value
exit status and output
GNU uniq writes adjacent-group results and returns nonzero on read/write errors. With -d or -u, an empty result can be successful; compare the chosen group output.
Working Example
Example Snippetlinux
LC_ALL=C sort labels.txt | uniq -c