The uniq command
Remove or count repeated lines. Collapses runs of identical lines that are next to each other into one. Repeats that are far apart are not touched, which is why uniq usually comes after sort.
Usage
uniq [OPTION]... [FILE]
Options
| -c, --count | put the number of times each line occurred in front of it |
|---|---|
| -d, --repeated | only print lines that were repeated |
| -u, --unique | only print lines that were not repeated |
| -i, --ignore-case | treat upper and lower case as the same |
Examples
sort names.txt | uniqEach name oncesort names.txt | uniq -cEach name with how often it appears
Learn it step by step
Related commands
learner@sandbox: ~bash (practice)
Note: Try uniq here: your home directory has sample files. Press Try beside an example, or type your own.
Enter runs · Tab completes names · ↑ ↓ step through history · Ctrl+L clears · type help for every command
A practice shell in your browser that behaves like bash on Linux for these commands. Nothing you type leaves the page.