May 2017
Beginner
552 pages
28h 47m
English
Using the -v argument, we can pass external values other than stdin to awk, as follows:
$ VAR=10000
$ echo | awk -v VARIABLE=$VAR '{ print VARIABLE }'
10000
There is a flexible alternate method to pass many variable values from outside awk. Consider the following example:
$ var1="Variable1" ; var2="Variable2"
$ echo | awk '{ print v1,v2 }' v1=$var1 v2=$var2
Variable1 Variable2
When an input is given through a file rather than standard input, use the following command:
$ awk '{ print v1,v2 }' v1=$var1 v2=$var2 filename
In the preceding method, variables are specified as key-value pairs, separated by a space, and (v1=$var1 v2=$var2 ) as command arguments to awk soon after the BEGIN, { }, and END ...