Example
87.140.79.42 - - [23/Jan/2024:09:00:46 +0100] "GET /monitoring/pings/ HTTP/1.1" 200 814 "-" "Ruby"
87.140.79.42 - - [23/Jan/2024:09:00:46 +0100] "GET /monitoring/pings/ HTTP/1.1" 200 814 "-" "Ruby"
87.140.79.41 - - [23/Jan/2024:09:00:46 +0100] "GET /monitoring/pings/ HTTP/1.1" 200 814 "-" "Ruby"
87.140.79.42 - - [23/Jan/2024:09:00:46 +0100] "GET /monitoring/pings/ HTTP/1.1" 200 814 "-" "Ruby"
Goal
Count and sort the number of requests for a single IP address.
Bash Command
awk '{ print $1}' test.log | sort | uniq --count
Result
1 87.140.79.41
3 87.140.79.42
Explain
awk '{ print $1}' test.log
87.140.79.42
87.140.79.42
87.140.79.41
87.140.79.42
sort
87.140.79.41
87.140.79.42
87.140.79.42
87.140.79.42
-
uniq --count
[1]
1 87.140.79.41
3 87.140.79.42
- [1] -c, --count: prefix lines by the number of occurrence
Posted by Emanuel to makandra dev (2024-01-23 07:59)