1.awk format
awk [Cutting symbol] '[/ pattern /] Function statement' [filename]
2. The output of a corresponding column
All $ 0, $ 1 the first column, the second column ...... $ 2
awk -F: '{print $1}' /etc/passw
3 corresponding to the output line
awk -F: 'NR==2{print "filename: "FILENAME, $0}' /etc/passwd
awk -F: 'NR==2{print "filename: "$1}' /etc/passwd
4. Specify delimiter -F
awk -F : 'NR==2{print "filename: "FILENAME, $0}' /etc/passwd
Multi separator awk -F "[:, /]" 'NR == 2 {print "filename:" FILENAME, $ 0}' / etc / passwd
The use of a plurality of spaces of regular filter
ifconfig |grep eth* | awk -F '[ ]+' '{print $1}'
6.awk Programming
Worth the number of files in the statistics, and the average
awk 'BEGIN{count=0;}{split($0,a,"\t");for(i in a){count+=a[i];times+=1;}}END{print times,count,count/times}' log_20191022194429