匹配root
awk 'BEGIN{FS=":"} $1~/root/' /etc/passwd
全部域匹配root
awk 'BEGIN{FS=":"} $0~/root/' /etc/passwd
全部域不匹配root
awk 'BEGIN{FS=":"} $0!~/root/' /etc/passwd
awk中的if语句
awk 'BEGIN{FS=":"} {if($3<$4) print $0}' /etc/passwd
多条件精确匹配
awk 'BEGIN{FS=":"} {if($3==10||$4~10) print $0}' /etc/passwd
多条件模糊匹配
awk 'BEGIN{FS=":"} {if($3~10||$4~10) print $0}' /etc/passwd
转换为浮点数
awk 'BEGIN {printf("%f\n",2010)}'
printf修饰符。prec的用法
awk 'BEGIN {printf("%10.3f\n",2009.1012)}'
awk 'BEGIN {printf("%10.3f\n",2009.1012)}'
转载于:https://my.oschina.net/xxchen/blog/3011796