Scroll to navigation

uniq(1) General Commands Manual uniq(1)

NAME

uniq - Report or omit repeated lines.

SYNOPSIS

uniq [-D|--all-repeated] [--group] [-w|--check-chars] [-c|--count] [-i|--ignore-case] [-d|--repeated] [-s|--skip-chars] [-f|--skip-fields] [-u|--unique] [-z|--zero-terminated] [-h|--help] [-V|--version] [files]

DESCRIPTION

Report or omit repeated lines.

OPTIONS

print all duplicate lines. Delimiting is done with blank lines. [default: none]

[possible values: none, prepend, separate]

show all items, separating groups with an empty line. [default: separate]

[possible values: separate, prepend, append, both]

compare no more than N characters in lines
prefix lines by the number of occurrences
ignore differences in case when comparing
only print duplicate lines
avoid comparing the first N characters
avoid comparing the first N fields
only print unique lines
end lines with 0 byte, not newline
Print help
Print version

EXTRA

Filter adjacent matching lines from INPUT (or standard input), writing to OUTPUT (or standard output).

Note: uniq does not detect repeated lines unless they are adjacent. You may want to sort the input first, or use sort -u without uniq.

VERSION

v(uutils coreutils) 0.7.0

EXAMPLES

Display each line once:

sort path/to/file | uniq

Display only unique lines:

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

Display only duplicate lines:

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

Display number of occurrences of each line along with that line:

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

Display number of occurrences of each line, sorted by the most frequent:

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

Compare only the first 10 characters on each line for uniqueness:

sort path/to/file | uniq [-w|--check-chars] 10

Compare text after the first 5 characters on each line for uniqueness:

sort path/to/file | uniq [-s|--skip-chars] 5

The examples are provided by the tldr-pages project <https://tldr.sh> under the CC BY 4.0 License. Please note that, as uutils is a work in progress, some examples might fail.

uniq (uutils coreutils) 0.7.0