一、awk內置字符串函數
gsub(r,s) 在整個$0中,用s代替r
gsub(r,s,t) 在整個t中,用s代替r #替換字符串
index(s,t) 返回s中字符串t的第一位置 #未用過
length(s) 返回s長度 #c語言strlen
match(s,r) 測試s是否包含匹配r的字符串 #c語言strcmp
split(s,a,fs) 使用分隔符fs將字符串s劃分爲指定序列a
sprint(fmt,exp) 輸出通過fmt格式化後的exp
substr(s,p) 返回字符串s中從p開始的後綴部分
substr(s,p,n) 返回字符串s中從p開始的長度爲n的後綴部分 #用截取第一個字符串和獲取某一段字符串php
二、printf格式化輸出
.prec 最大字符串長度,或小數點右面的位數
%c ASCII字符
%d 整型
%e 科學計數法
%f 浮點型 #使用小數點後2位%.2f (用於除法後)
%g awk決定哪一種浮點數轉換e或者f
%o 八進制
%s 字符串
%x 十六進制html
awk -F '[ ]' '/\/api_jsonrpc.php/{ipaddr[$1$7]++}END{for(i in ipaddr){print i,ipaddr[i]}}' access_log #查看/api_jsonrpc.php被訪問的次數json
參考連接:
https://www.cnblogs.com/DengGao/p/5935719.html
https://www.cnblogs.com/emanlee/p/3327576.html
http://www.zsythink.net/archives/tag/awk/api