Environment variables in GAWK
In this section, we discuss the various GAWK-specific variables. They are not available in the original AWK distribution. However, on modern Linux systems, generally these options will work because AWK is set as a symbolic link to the GAWK executable.
ARGIND
ARGIND
represents the index in the ARGV
arrayto retrieve thecurrent file being processed.When we operate with one file in AWK script, the ARGIND
will be 1
, and ARGV[ARGIND]
will return the filename that is currently being processed.
In the following example, we print the value of ARGIND
and the current filename using ARGV[ARGIND]
as follows:
$ vi argind.awk END { print "ARGIND : ", ARGIND; print "Current Filename : ", ARGV[ARGIND];
} $ awk -f argind.awk
The output of the execution of the preceding code is as follows:
ARGIND : 1 Current Filename : cars.dat
We have printed the value stored in ARGIND
in the END
block here so that it is not printed in a loop when each line of cars.dat
is processed.So...