0

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?

Olivier Pons
  • 15,363
  • 26
  • 117
  • 213
  • I don't think there was any need to delete your latest question - it might have been unclear to one or two people, but I'm sure you could have explained it. Deleting a question unnecessarily causes annoyance to people who are in the middle of writing a comment/answer. For reference, my comment response was: "I wonder if implementing Serializable lets it reconstruct things that ordinary serialisation cannot re-initialise, like internal Resources. It might be pertinent to the question though: in what way did your first attempt not work?" – halfer Apr 13 '14 at 21:40
  • You're right, I'm going to re-ask it another way. – Olivier Pons Apr 15 '14 at 06:58

2 Answers2

3

sort | uniq -c is what you are looking for.

ypnos
  • 50,202
  • 14
  • 95
  • 141
1

try this:

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