sort | uniq -c
is what you are looking for.
Count number of occurences group by
-
28-06-2023 - |
Question
I need to count the number of times each occurence appear, not only 'group by
' which I make with sort
:
>>> cat /var/log/squid/access.log* | awk '{ print $NF }' | sort -u
TCP_CLIENT_REFRESH_MISS:DIRECT
TCP_DENIED:NONE
TCP_HIT:NONE
TCP_IMS_HIT:NONE
TCP_MEM_HIT:DIRECT
TCP_MEM_HIT:NONE
TCP_MISS:DIRECT
TCP_MISS:NONE
TCP_NEGATIVE_HIT:NONE
TCP_REFRESH_HIT:DIRECT
TCP_REFRESH_MISS:DIRECT
>>>
How would you do?
Solution
OTHER TIPS
try this:
awk '{a[$NF]++}END{for (i in a) print a[i],i|"sort"}' /var/log/squid/access.log*
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow