> awk '{print $1}' rumenz.txt
> awk '{print $1,$2}' rumenz.txt
> awk '{print $NF}' rumenz.txt
> awk 'END{print NR}' rumenz.txt
> awk 'NR==1{print}' rumenz.txt
NR是指awk正在处理的记录位于文件中的位置(行号)
> sed -n '3,1p' rumenz.txt | awk '{print $2}'
> awk 'NF' rumenz.txt
> awk 'b=!b' rumenz.txt
> awk -F '#' 'if(NF==3){print}' rumenz.txt
NF是指awk正在处理的记录包含几个域(字段),这与域分隔符有关,默认为空
> cat /etc/passwd | awk -F ":" '{print $1" : "$7}'
> cat /etc/passwd | awk '{count++}END{ print count}'
> ls -l | awk 'BEGIN{size=0}{size=size+$5}END{print size}'
> ls -l | awk 'BEGIN{size=0}{size=size+$5}END{print size}'
> netstat -tunlp | awk '/^tcp/{++a[$6]}END{for(i in a) print i,a[i]}'
> awk '/^[^$]/ {print $0}' rumenz.txt
> cat 1.txt123
> cat 1.txt | awk '{a+=$1}END{print a}'
> cat 1.txt | awk '{a+=$1}END{print a/NR}'
> cat 1.txt | awk 'BEGIN{a=0}{if($1>a) a=$1 fi}END{print a}'
网友评论