awk '{h[$1]++}END{for(pol in h)print pol,h[pol]}' access.log |sort -rnk2|head
awk -F: -vOFS=":" '{tmp=$1;$1=$NF;$NF=tmp;print }' /etc/passwd
vofs 把空格间隔 换成:
awk -F "[ :]"+ '$1~/Zhang/{print$1,$2,$5}' reg.txt
Zhang Dandan 100
Zhang Xiaoyu 90
awk -F "[ :]"+ '$3~/1$|5$/{print$1 $2}' reg.txt
/[15]$/
awk '$2~/Xiaoyu/{gsub(/:/,"$",$NF);print$NF}' reg.txt 替换
特殊模式
BEGIN{} 在被awk读取前执行
END