uniq
text processingLinux/Unix
The uniq command is one of the most frequently used commands in Linux/Unix-like operating systems. uniq Report or omit repeated lines
Quick Reference
Command Name:
uniq
Category:
text processing
Platform:
Linux/Unix
Basic Usage:
uniq [options] [arguments]
Common Use Cases
Syntax
uniq [OPTION]... [INPUT [OUTPUT]]
Options
Option | Description |
---|---|
-c, --count |
Prefix lines with the number of occurrences |
-d, --repeated |
Only print duplicate lines, one for each group |
-D, --all-repeated[=METHOD] |
Print all duplicate lines. METHOD can be 'none' (default), 'prepend', or 'separate' |
-f, --skip-fields=N |
Avoid comparing the first N fields |
--group[=METHOD] |
Show all items, separating groups with an empty line. METHOD can be 'separate' or 'prepend' |
-i, --ignore-case |
Ignore differences in case when comparing |
-s, --skip-chars=N |
Avoid comparing the first N characters |
-u, --unique |
Only print unique lines |
-z, --zero-terminated |
Line delimiter is NUL, not newline |
-w, --check-chars=N |
Compare no more than N characters in lines |
--help |
Display help and exit |
--version |
Output version information and exit |
Examples
How to Use These Examples
The examples below show common ways to use the uniq
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
# Basic Examples Basic
# Remove duplicate consecutive lines from a file
uniq input.txt