格式:
awk [option] ‘awk_script’ input_file1 [input_file2 ...]
awk ‘BEGIN { actions } awk_pattern1 { actions }.....awk_patternN { actions } END
{ actions }’ input_file
其中BEGIN { actions } 和 END { actions }是可選的。
#把源修改成目錄對哪些進行修改
ls $file_path/*.jpg|awk -F '_ddl' '{print "mv" " " $0 " " $1".jpg"}'|bash #刪除名字字段
ls $file_path/*.jpg|awk -F '.jpg' '{print "mv" " " $0 " " $1"_ddl.jpg"}'|bash #增加名字字段
#查看http的併發請求數及其TCP連接狀態:
netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
#統計服務器連接數的狀態
netstat -an | awk '/^tcp/ {++S[$NF]} END {for (a in S) print a,S[a]}'
netstat -an | awk '/^tcp/ {print $6}'|sort |uniq -c|sort -nr
ss -an | awk '{print $2}'|sort|uniq -c |sort
ss -n|awk '/^tcp/{++s[$2]}END{for (i in s) print s[i],i}'
#統計所有到80端口的ESTABLISHED狀態鏈接的個數
netstat -an|grep 'ESTABLISHED'|grep '80'|awk '/^tcp/ {print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -nr
#查看IP連接數
netstat -n | awk '/^tcp/ {print $5}'| awk -F: '{print $1}' | sort | uniq -c | sort -rn
netstat -an|awk '/^tcp/{print $5}'|awk -F: '{++s[$1]}END{for (i in s) print s[i],i}'
#統計apache日誌文件(access_log)中某一天中每個URL的訪問次數
awk '{print $11}' access_log|sort|uniq -c|sort -n
#用tcpdump嗅探80端口的訪問看看誰最高
tcpdump -i eth0 -tnn dst port 80 -c 1000 | awk -F"." '{print $1"."$2"."$3"."$4}' | sort | uniq -c | sort -nr |head -20