uniq Command Builder — Linux uniq Examples
Linux uniq Command Builder (Filter Duplicate Lines)
The uniq command is used to filter adjacent duplicate lines in Linux. This interactive uniq Command Builder helps you generate precise uniq commands for deduplication and frequency analysis.
🚀 What is the uniq Command?
The uniq command allows you to:
- Remove adjacent duplicate lines from sorted input
- Count occurrences of each unique line
- Show only duplicated or only unique lines
- Compare lines while skipping fields or characters
⚙️ Basic Syntax
uniq [options] [INPUT [OUTPUT]]
sort file.txt | uniq [options]🧠 How to Use This uniq Command Builder
This tool helps you:
- Choose counting (
-c), duplicate-only (-d), or unique-only (-u) modes - Ignore case with
-ior skip fields with-f,-s,-w - Build the correct
sort | uniqpipeline - Generate a ready-to-use uniq command
Workflow
- Sort your input so duplicates become adjacent
- Pick a display mode: default,
-c,-d, or-u - Add matching tweaks like
-i,-f,-s, or-w - Copy generated command
🔧 Common uniq Usage Patterns
Remove Duplicates (Sort First)
sort names.txt | uniqCount Occurrences of Each Line
sort names.txt | uniq -cRank Lines by Frequency (Most Common First)
sort names.txt | uniq -c | sort -rnShow Only Duplicated Lines
sort names.txt | uniq -dShow Only Truly Unique Lines
sort names.txt | uniq -uCase-Insensitive Dedup With Field Skipping
sort data.txt | uniq -i -f 1 -s 2 -w 10⚠️ Important Notes
- The #1 uniq pitfall is adjacent-only matching:
uniqcompares only neighboring lines, so unsorted input keeps scattered duplicates - Always sort first: the safe pattern is
sort file | uniq, never bareuniq fileon unsorted data - Counting:
-cprefixes each line with its occurrence count - Filtering:
-dkeeps only lines seen more than once,-ukeeps only lines seen exactly once - Fuzzy matching:
-iignores case,-f Nskips N fields,-s Nskips N characters,-w Ncompares only the first N characters
✅ Pro Tips
- Pipe
uniq -cintosort -rnfor instant frequency rankings - Use
-dto find duplicates before deciding what to delete - Use
-uto isolate lines that appear exactly once - Combine
-iwith-wfor case-insensitive prefix grouping