Count Duplicates in Shell
Level 236 keystrokes
Counts identical lines in access.log (here IP addresses) and lists the most frequent first; uniq only merges adjacent duplicates, so sort runs first.
Shell code
# sort puts identical lines next to each other so uniq -c can count them# sort -rn orders by that count, most frequent first (156 192.168.1.1)1sort access.log | uniq -c | sort -rnOutput
156 192.168.1.1
89 192.168.1.2
45 192.168.1.3Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this Shell code and how often they appear.
-× 2|× 2.× 1