Skip to content

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.

A practice shell in your browser that behaves like bash on Linux for these commands. Nothing you type leaves the page.

Usage

uniq [OPTION]... [FILE]

Options

-c, --countput the number of times each line occurred in front of it
-d, --repeatedonly print lines that were repeated
-u, --uniqueonly print lines that were not repeated
-i, --ignore-casetreat upper and lower case as the same

Examples

  • sort names.txt | uniqEach name once
  • sort names.txt | uniq -cEach name with how often it appears

Learn it step by step