0

I want to get the record count in every hour from log file. here is the sample data;

001:2017-05-23 00:00:01 002:10.10.10.63
001:2017-05-23 00:00:03 002:10.10.10.63
001:2017-05-23 00:00:05 002:10.10.10.63
001:2017-05-23 00:00:07 002:10.10.10.63
001:2017-05-23 00:00:09 002:10.10.10.63
001:2017-05-23 01:00:12 002:10.10.10.63
001:2017-05-23 01:00:14 002:10.10.10.63

from above data output should be;

00 = 5
01 = 2
1
cut -f2 -d' ' logfile
| cut -f1 -d:
| sort
| uniq -c
| sed 's/ *\([0-9]\+\) \([0-9][0-9]\)/\2 = \1/'
| sort
  1. only outputs the time.
  2. only extracts the hours.
  3. sort the output - needed by the following line
  4. counts occurrences of each hour, outputs count hour
  5. fixes the formatting
  6. sorts by hours

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.