linux命令awk

本文发布时间: 2019-Mar-22
熟悉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


(以上内容不代表本站观点。)
---------------------------------
本网站以及域名有仲裁协议。
本網站以及域名有仲裁協議。

2024-Mar-04 02:09pm
栏目列表