Saturday, February 5, 2022

[SOLVED] Grep logs for occurrences per second

Issue

I am trying to search logs for a range of time looking for the number of occurrences a specific account has. For instance I am running this now:

sed ‘/23:50:28/,/23:55:02/! d’ log.log | grep account_number | wc -l

Which nicely returns the total number of times this account might have entries given the time frame per second. My question is how can I also get a list of all those occurrences by each time entry? Example:

23:50:28 - 2
23:50:29 - 1
23:50:30 - 3
etc.
etc.

Thanks


Solution

awk to the rescue!

awk ‘/23:50:28/,/23:55:02/{if(/account_number/) a[$1]++}
     END{for(k in a) print k " - " a[k]}' log | sort

obviously not tested since there is no sample input.



Answered By - karakfa
Answer Checked By - Pedro (WPSolving Volunteer)