下面代码,awk中ARGIND为什么没有从 0 开始,而是从 1 开始?


[root@localhost test]# awk 'BEGIN{for (i=0;i<ARGC;i++) print "ARGV["i"] = "ARGV[i]}{print ARGV[ARGIND],ARGIND,ARGC,$0}' [abc].txt
ARGV = awk
ARGV[1] = a.txt
ARGV[2] = b.txt
ARGV[3] = c.txt
a.txt 1 4 a
a.txt 1 4 b
a.txt 1 4 c
b.txt 2 4 d
b.txt 2 4 e
b.txt 2 4 f
c.txt 3 4 g
c.txt 3 4 h
c.txt 3 4 i
[root@localhost test]#

awk shell

Caiych 11 years, 1 month ago

ARGIND的定义就是这样的。
ARGIND: The index in ARGV of the current file being processed. Every time
gawk opens a new data file for processing, it sets ARGIND to the index in ARGV of the file name.

处理a.txt时,a.txt是ARGV[1],那ARGIND应该就是1了。

天地君亲师 answered 11 years, 1 month ago

Your Answer