Count number of times that each API version shows up in log file [closed]

Develop script which receives data from localhost on port 33001 and finds how many times distinct API version is requested and print it on a screen.

Sample log is: 736443 /api/2.3 182294 /api/2.3 736443 /api/2.3/security 397832 /api/3.0 736443 /api/2.3 182294 /api/3.0 736443 /api/2.3/logging 736443 /api/2.3 291187 /api/2.3 736443 /api/3.0/security 182294 /api/2.3 397832 /api/3.0/logging

First field is IP-address, second one is user id and last one is path to resource.


Assuming you care only about the version and not the whole path:

$ awk -F/ '{count[$3]++} END {for (v in count) print v, count[v]}' file
2.3 8
3.0 4

Splitting fields on /, the version number seems to be the third field in all lines.

Leave a Reply

Your email address will not be published. Required fields are marked *