awk 'BEGIN{} {主输入循环} END{}'
在不需要在文件一开始和结束做事情的时候,BEGIN和END可以省去
awk '{max = {$1 > $3} ? $1: $3: print max}' test
if - else
awk '{if ($1 > 100) print $1 "bad" ; else print "ok"}' test
awk '{if ($1 > 100){ count++; print $1} else {count--; print $2}' test
#最大qps
cat access.log.20160821 | grep "Apache" | awk -F '[' '{print $2}'|awk -F ']' '{print $1}' | awk 'BEGIN{cur = $0;count=0;max=0}{if(cur==$0)count++;else count=0;cur=$0;max = (max>count)?max:count} END {print max}'