Linux-命令-awk

来源:互联网 发布:淘宝刷单任务书模板 编辑:程序博客网 时间:2024/06/06 08:31

熟悉awk和print语法

fuhui@ubuntu:~$ ls -lh | awk '{print $5 }'

BEGIN和END被包裹在一个单引号内

fuhui@ubuntu:~$ ls -lh | awk 'BEGIN { count=0; print "start:" count}' 'END { print "total:" , count}'start:0fuhui@ubuntu:~$ ls -lh | awk 'BEGIN { count=0; print "start:" count} END { print "total:" , count}'start:0total: 0

在BEGIN和END之间插入语句

fuhui@ubuntu:~$ ls -lh | awk 'BEGIN { count=0; print "start:" count} {count=count+$5; print count} END { print "total:" , count}'

逻辑段之间使用分号相隔。END和BEGIN后紧跟{}比较美观

awk -F ':' 'BEGIN{ count=0 } { name[count]=$1; count=count+1 } END{ for(i=0;i<NR;i++) print i name[i]}' /etc/passwd
0 0
原创粉丝点击