bash - Count number of occurrences of token in a file -


i have server access log, timestamps of each http request, i'd obtain count of number of requests @ each second. using sed, , cut -c, far i've managed cut file down timestamps, such as:

22-sep-2008 20:00:21 +0000
22-sep-2008 20:00:22 +0000
22-sep-2008 20:00:22 +0000
22-sep-2008 20:00:22 +0000
22-sep-2008 20:00:24 +0000
22-sep-2008 20:00:24 +0000

what i'd love number of times each unique timestamp appears in file. example, above example, i'd output looks like:

22-sep-2008 20:00:21 +0000: 1
22-sep-2008 20:00:22 +0000: 3
22-sep-2008 20:00:24 +0000: 2

i've used sort -u filter list of timestamps down list of unique tokens, hoping use grep like

grep -c -f <file containing patterns> <file> 

but produces single line of grand total of matching lines.

i know can done in single line, stringing few utilities ... can't think of which. know?

i think you're looking for

uniq --count 

-c, --count prefix lines number of occurrences


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -