awk命令详解

free -h|awk ‘NR==2‘
 free -h|awk ‘NR==3‘
 free -h|awk ‘NR==2{print $NF}‘
 free -h|awk ‘NR==2{print $NF,$2}‘
 free -h|awk ‘NR==2{print $NF/$2}‘
 free -h|awk ‘NR==2{print $NF/$2*100}‘
 free -h|awk ‘NR==2{print int($NF/$2*100)}‘
awk ‘$3~/^41/{print $1,$2,$3}‘ awk_test.txt 
 awk ‘$3~/1$|5$/{print $1$2}‘ awk_test.txt 
 awk ‘$3~/1$|5$/{print $1,$2}‘ awk_test.txt 
 awk ‘$3~/1$|5$/{print $1,$2}‘ awk_test.txt -n
 awk ‘$3~/1$|5$/{print $1,$2}‘ awk_test.txt|column -n
 awk ‘$3~/1$|5$/{print $1,$2}‘ awk_test.txt|column -t
 awk ‘$3~/[15]$/{print $1,$2}‘ awk_test.txt|column -t
 awk ‘$3~/(1|5)$/{print $1,$2}‘ awk_test.txt|column -t
 !
 cat awk_test.txt 
 awk ‘$2~/Xiaoyu/{gsub(/:/,"$",$NF),print $NF}‘ awk_test.txt 
 awk ‘$2~/Xiaoyu/{gsub(/:/,"$",$NF);print $NF}‘ awk_test.txt 
 history
 vim awk_test.txt 
 cat awk_test.txt 
 awk ‘/^#|^$/‘ awk_test.txt 
 awk ‘/!^#|^$/‘ awk_test.txt 
 awk ‘!/^#|^$/‘ awk_test.txt 
 awk ‘$0~/^#|^$/‘ awk_test.txt 
 awk ‘$0!~/^#|^$/‘ awk_test.txt 
 iP a
 ip a
 ip a s
 ip a s eth0
 ip -n
 ip --h
 ip a s --h
 man ip
 ip a sh
 ip a sh eth0
 ip a sh eth0|awk -F "[/]{print $2}"
 ip a sh eth0
 ip a sh eth0|awk -F "/" ‘NR==2‘
 ip a sh eth0|awk -F "/" ‘NR==3‘
 ip a sh eth0|awk -F "/" ‘NR==3{print $2}‘
 ip a sh eth0|awk -F "[ /]+" ‘NR==3{print $2}‘
 ip a sh eth0|awk -F "[ /]+" ‘NR==3{print $3}‘
 ip a sh eth0|awk -F "[ /]+" ‘NR==3{print $1}‘
 ip a sh eth0|awk -F "[ /]+" ‘NR==3{print $3}‘
 hostname -i
 awk ‘BEGIN{print "姓","名","QQ号","捐款记录"}‘
 awk ‘BEGIN{print "姓","名","QQ号","捐款记录"}{print $0}‘ awk_test.txt 
 awk ‘BEGIN{print "姓","名","QQ号","捐款记录"}{print $0}‘ awk_test.txt |coulmn -t
 awk ‘BEGIN{print "姓","名","QQ号","捐款记录"}{print $0}‘ awk_test.txt |column -t
 awk ‘BEGIN{print "姓","名","QQ号","捐款记录"}‘ awk_test.txt |column -t
 awk ‘BEGIN{print "姓","名","QQ号","捐款记录"}{print $0}‘ awk_test.txt |column -t
 awk ‘BEGIN{print 1+1}‘
 awk ‘BEGIN{print 1-9}‘
 awk ‘BEGIN{print 1*9}‘
 awk ‘BEGIN{print 1/9}‘
 echo $((1+9))
 echo $((1/9))
 cat awk_test.txt 
 awk ‘BEGIN{FS=":"}{print $2}END{print "操作结束"}‘ awk_test.txt 
 awk -vqhy=123 ‘{print qhy}‘ awk_test.txt 
 grep ‘^$‘ /etc/services 
 grep ‘^$‘ /etc/services -c
 awk ‘/^$/{i=i+1;print i}‘ /etc/services 
 awk ‘/^$/{i++;print i}‘ /etc/services 
 awk ‘/^$/{i++}END{print i}‘ /etc/services 
 cat /etc/passwd
 awk ‘$NF~/bash/‘ /etc/passwd
 awk ‘$NF~/bash/{i=i+1}END{print i}‘ /etc/passwd
 awk ‘$NF!~/bash/{i=i+1}END{print i}‘ /etc/passwd
 awk ‘$NF!~/bash/‘ /etc/passwd
 awk ‘$NF!~/bash/{i=i+1}END{print i}‘ /etc/passwd
 seq 10
 awk ‘{sum=sum+$n,print sum}‘
 awk ‘{sum=sum+$n;print sum}‘
 seq 10|awk ‘{sum=sum+$n;print sum}‘
 cat awk_test.txt 
 awk -F ":" ‘{print $2,$NF}‘ awk_test.txt 
 awk -F ":" ‘{print $2,$NF}‘ awk_test.txt |awk ‘{sum=sum+$n;print $n}‘
 awk -F ":" ‘{print $2,$NF}‘ awk_test.txt |awk ‘$1~{sum=sum+$n;print $n}‘
 awk -F ":" ‘{print $2,$NF}‘ awk_test.txt |awk ‘$1~{sum=sum+$n;print}‘
 awk -F ":" ‘{print $2,$NF}‘ awk_test.txt |awk ‘{sum=sum+$n}‘
 awk -F ":" ‘{print $2,$NF}‘ awk_test.txt |awk ‘{sum=sum+$n;print $0}‘
 seq 10|awk ‘{sum=sum+$1;print sum}‘
 awk -F ":" ‘{print $2,$NF}‘ awk_test.txt |awk ‘{sum1=sum1+$1;sum2=sum2+$2;print sum1,sum2}‘
 vim awk_test.txt 
 awk -F ":" ‘{print $2,$NF}‘ awk_test.txt |awk ‘{sum1=sum1+$1;sum2=sum2+$2;print sum1,sum2}‘
 awk -F ":" ‘BEGIN{print "第一次捐款总额","第二次捐款总额"}{print $2,$NF}‘ awk_test.txt |awk ‘{sum1=sum1+$1;sum2=sum2+$2;print sum1,sum2}‘
 awk -F ":" ‘{print $2,$NF}‘ awk_test.txt |awk ‘BEGIN{print "第一次捐款总额","第二次捐款总额"}{sum1=sum1+$1;sum2=sum2+$2;print sum1,sum2}‘
 awk -F ":" ‘{print $2,$NF}‘ awk_test.txt |awk ‘BEGIN{print "第一次捐款总额","第二次捐款总额"}{sum1=sum1+$1;sum2=sum2+$2;print sum1,sum2}‘|column -t

相关推荐