[root@centos ~]# awk '{print NF,NR,$0} END {print FILENAME}' textfile
6 1 Unusual occurrences happened at the fair.
12 2 Patty won fourth place in the 50 yard dash fair and square.
5 3 Occurrences like this are rare.
5 4 The winning ticket is 55222.
10 5 The ticket I got is 54333 and Dee got 55544.
13 6 Guy fell down while running around the south bend in his last event.
textfile
输出 域或字段数 已读的记录数 记录内容,最后输出 文件名。
[root@centos ~]# awk '{if (NR>0 && $3~/ticket/) print $0}' textfile
The winning ticket is 55222.
输出第3个域或字段是ticket的记录,或者说至少存在一条记录且第3个字段或域是ticket。
[root@centos ~]# echo $PWD | awk -F/ '{print $NF}'
root
显示当前目录名,其中$NF代表最后一个域或字段的内容。