|
NR 和 FNR 在只有一个文件时意思是一致的,都表示当前文件的记录数。但是当有多个输入文件时,NR 表示所有文件的总共记录数,而 FNR 只表示当前文件的记录数。
先看两个测试文件的内容:
第 1 个文件共 4 行,即 4 条记录:$ cat employee.txt
1 director 2 30000
2 manager 4 20000
3 engineer 8 9000
4 technician 20 4500[/qutoe]
第 2 个文件共
[quote]$ cat employee.txt
1 director 2 30000
2 manager 4 20000
3 engineer 8 9000
4 technician 20 4500
那么运行下面的命令可以验证上面所述:$ awk '{print FILENAME, NR, FNR}' tmp.txt employee.txt
tmp.txt 1 1
tmp.txt 2 2
tmp.txt 3 3
tmp.txt 4 4
tmp.txt 5 5
tmp.txt 6 6
tmp.txt 7 7
tmp.txt 8 8
employee.txt 9 1
employee.txt 10 2
employee.txt 11 3
employee.txt 12 4 |
|