需求以下:php
有日誌access.log,部份內容以下:curl
127.0.0.1 - - [03/Jul/2018:00:00:01 +0800] "GET / HTTP/1.1" 200 612 "-" "curl/7.29.0"
127.0.0.1 - - [03/Jul/2018:00:01:48 +0800] "GET /1.php HTTP/1.1" 200 19 "-" "curl/7.29.0"
192.168.1.9 - - [04/Jul/2018:23:43:19 +0800] "GET / HTTP/1.1" 200 13 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36"
192.168.1.9 - - [04/Jul/2018:23:43:19 +0800] "GET /favicon.ico HTTP/1.1" 404 571 "http://192.168.1.5/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36"
192.168.1.9 - - [04/Jul/2018:23:45:30 +0800] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36"
192.168.1.9 - - [04/Jul/2018:23:45:32 +0800] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36"
192.168.1.9 - - [04/Jul/2018:23:45:33 +0800] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36"
192.168.1.9 - - [04/Jul/2018:23:45:34 +0800] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36"
192.168.1.9 - - [04/Jul/2018:23:45:35 +0800] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36"url
編譯出每一個IP的訪問量有多少?日誌
參考解答以下code
cut -d ' ' -f 1 access.log | sort -n | uniq -c | sort -nr
# sort -n按數字方式排序 # uniq -c前必定要先排序 # sort -nr 倒序 awk '{print $1}' access.log | sort -n | uniq -c | sort -nr
awk '{ip[$1]++}END{for(i in ip){print i,ip[i]}}' access.log