uniq
remove or count repeatsuniq removes duplicate lines — but only when the duplicates are next to each other. That is why it is always fed from sort. With -c it counts how often each line occurred.
sort | uniq -c | sort -nr turns any list into a ranking of what occurs most.
At the terminal
Read the session first, then the notes: each numbered line in the output is answered by the note with the same number.
What the numbered lines are telling you
192.0.2.7 appears twice in the output because, in the file, another line sat between its occurrences.
sort puts identical lines together; uniq -c then collapses each run and prints how many it replaced.
A second sort, numeric and reversed, orders by the number in front. head keeps the top one: the most frequent visitor.
Switches
A switch changes how the command behaves. These are the ones used day to day; man uniq lists the rest. Single-letter switches can usually be joined, so -l -a may be written -la.
-c- Count: prefix each line with the number of times it occurred.
-d- Print only lines that are repeated.
-u- Print only lines that are not repeated.
-i- Ignore case when comparing.
Variations worth knowing
The same tool, pointed at a narrower question. These four cover most of what it is reached for day to day.
sort file.txt | uniq -dPrints only the lines that occur more than once.
sort file.txt | uniq -uPrints only the lines that occur exactly once.
sort file.txt | uniq -iTreats upper and lower case as the same.
cut -d" " -f1 access.log | sort | uniq -c | sort -nr | headThe ten addresses making the most requests to a web server.
In cybersecurity
Counting repeats is how a pattern is pulled out of a noisy log.
Failed-login lines reduced to source addresses, then sort | uniq -c | sort -nr, lists the attackers by number of attempts.
The lines that occur once — uniq -u — are often the unusual event: a single request to an odd path, a process seen on one host only.
Without sorting, the same value is counted in several separate runs and the totals are meaningless.