计算出现次数

时间:2014-04-05 23:45:12

标签: linux shell find-occurrences

我需要计算每次出现的次数,而不仅仅是我使用group by制作的“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
>>>

你会怎么做?

2 个答案:

答案 0 :(得分:3)

sort | uniq -c正是您要找的。

答案 1 :(得分:1)

试试这个:

awk '{a[$NF]++}END{for (i in a) print a[i],i|"sort"}' /var/log/squid/access.log*