uniq

Output the unique lines from the given input or file. Since it does not detect repeated lines unless they are adjacent, we need to sort them first. More information: <https://www.gnu.org/software/coreutils/uniq>.

Install

All systems
curl cmd.cat/uniq.sh
Debian Debian
apt-get install coreutils
Ubuntu
apt-get install coreutils
Alpine
apk add coreutils
Arch Arch Linux
pacman -S coreutils
image/svg+xml Kali Linux
apt-get install coreutils
CentOS
yum install coreutils
Fedora
dnf install coreutils
Windows (WSL2)
sudo apt-get update sudo apt-get install coreutils
OS X
brew install coreutils
Raspbian
apt-get install coreutils
Docker
docker run cmd.cat/uniq uniq powered by Commando

Output the unique lines from the given input or file. Since it does not detect repeated lines unless they are adjacent, we need to sort them first. More information: <https://www.gnu.org/software/coreutils/uniq>.

  • Display each line once:
    sort path/to/file | uniq
  • Display only unique lines:
    sort path/to/file | uniq -u
  • Display only duplicate lines:
    sort path/to/file | uniq -d
  • Display number of occurrences of each line along with that line:
    sort path/to/file | uniq -c
  • Display number of occurrences of each line, sorted by the most frequent:
    sort path/to/file | uniq -c | sort -nr

© tl;dr; authors and contributors