uniq
The command that collapses runs of identical adjacent lines into one; -c prefixes each with how many there were.
In more detail
It only compares neighbouring lines, so sort the input first. sort | uniq -c | sort -nr is the classic way to count how often each value appears.
Related terms
- sort command — The sort command, which puts lines in order, alphabetically by default.
- pipe — The | operator, which connects one command's standard output to the next command's standard input so they run together.
Taught in
- Reshaping Text: cut, sort, uniq, tr, sed, awk — Bash Scripting & Command Line Automation
- The Alert That Came An Hour Late — Confluent Apache Kafka Certifications (CCDAK and CCAAK) Exam Prep
- Forty Minutes To Start — Confluent Apache Kafka Certifications (CCDAK and CCAAK) Exam Prep
- Sixty Questions, One Wrong Flag Each — LPIC-1 Linux Administrator (101-500 and 102-500) Exam Prep