O'Reilly logo

Learning AWK Programming by Shiwang Kalkhanda

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

ARGC and ARGV

The ARGC and ARGV variables are used to pass arguments to the AWK script from the command line.

ARGC specifies the total number of arguments passed to the AWK script on the command line. It always has a value of 1 or more, as it counts the program name as the first argument.

The AWK script filename specified using the -f option is not counted as an argument. If we declare any variable on the command line, it is counted as an argument in GAWK:

$ awk 'BEGIN { print "No of arguments =", ARGC }' one two three four

The output of the execution of the preceding command is as follows:

No of arguments = 5 

ARGV is an array that stores all the arguments passed to the AWK command, starting from index 0 through to ARGCARGV[0] always contains ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required