NF、$NF、FR、FNR举例说明

NF当前处理数的个数

[root@VM_207_144_centos bin]# echo a b c | awk '{print NF}'

3


$NF当前处理数中的最后一位数

[root@VM_207_144_centos bin]# echo a b c | awk '{print $NF}'

c


FR当前处理行中的所指定的行数

[root@VM_207_144_centos bin]# curl "http://127.0.0.1/nginxstatus" 2> /dev/null | awk NR==2 | awk '{print $3}'

handled

[root@VM_207_144_centos bin]# curl "http://127.0.0.1/nginxstatus" 

Active connections: 1 

server accepts handled requests

 148 148 148 

Reading: 0 Writing: 1 Waiting: 0 


FNR当前处理行的行数

[root@VM_207_144_centos bin]# curl "http://127.0.0.1/nginxstatus" 2> /dev/null | awk '{print FNR}'

1

2

3

4

[root@VM_207_144_centos bin]# curl "http://127.0.0.1/nginxstatus" 2> /dev/null | awk NR==2 | awk '{print FNR}'

1