1.$3匹配到fangdd.com,打印改行所有内容

awk '{if($3==fangdd.com) print $0}’ filename

2.匹配到fangdd.com后打印改行的$1

awk '/fangdd.com/ {print $1}' filename

3.匹配到$3为404后打印改行的$1

awk '$3 == 404 {print $1}' filename

4.打印出Nignx的时间,域名,URL,IP,并以IP排序,取唯一

awk '{print $1,$7,$(NF-2),$5}' access.log|cut -d ":" -f 1,2,3,4|awk '{print $1,$4,$2,$3}'| awk '{count[$4]++}; END{for(name in count) print count[name],$1,$2,$3,name}' |sort -rn|head -10

5.$4是$body_bytes_sent/$bytes_sent,nginx里分别代表如下:

$body_bytes_sent:nginx返回给客户端的字节数,不含响应头.

$bytes_sent:nginx返回给客户端的总字节数

$4取值后是123123/7834这样的数字,后面的$2是把返回给客户端的总字节数相加,最终获得一个值,一般用来计算日志里所有请求的总消耗流量

cat /tmp/1700.log| awk '{print $4}' | awk -F'/' '{byte+=$2}END{print byte}'

6. 已建立连接的同一IP连接数

netstat -na|grep EST|grep -v 192.168.222|grep -v 101.251.100|grep -v 211.144.118.118|awk '$5 ~ /[0-9]+:[0-9]+/ {print $5}' |awk -F ":" -- '{print $1}' |sort -n|uniq -c |sort -n|tail


7.根据IP排序,列出时间,URL,IP,域名

awk '{print $1,$7,$(NF-2),$5}' access.log|cut -d ":" -f 1,2,3,4|awk '{print $1,$4,$2,$3}'| awk '{count[$4]++}; END{for(name in count) print count[name],$1,$2,$3,name}' |sort -rn|head -10