GNU uniq Cheatsheet
#
GNU uniq
is a command-line utility that filters adjacent matching lines from a file.
Basic Usage
#
Command/Option | Example | Description |
---|
uniq file.txt | uniq data.txt | Remove duplicate lines from a file |
uniq -c file.txt | uniq -c data.txt | Precede each line with the number of occurrences |
uniq -d file.txt | uniq -d data.txt | Only print duplicate lines |
Sorting
#
Command/Option | Example | Description |
---|
`sort file.txt | uniq` | `sort data.txt |
uniq -u file.txt | uniq -u data.txt | Only print lines that are not repeated |
Field Specific
#
Command/Option | Example | Description |
---|
uniq -f1 file.txt | uniq -f1 data.txt | Skip the first field when comparing lines |
uniq -s5 file.txt | uniq -s5 data.txt | Skip the first 5 characters when comparing lines |
Ignore Case
#
Command/Option | Example | Description |
---|
uniq -i file.txt | uniq -i data.txt | Ignore case when comparing lines |
This cheatsheet provides essential GNU uniq
commands for filtering duplicate lines from files.