gawk and nawk support the v option to import shell variables.
ex: gawk -v var=$myvar ' {printf "%s\n", var}'
However this only works with scalars,not arrays.
You would have to use something like:
function processArray() {
myarray[1]=1
myarray[2]=1
myarray[3]=1
for x in "${[myarray[@]}"
do
awk -v var=${myarray[$x]} ' {printf "%s\n",var}' filename
done
}
I knew about the -v feature and was using it till i hit the limitation of command line args length. So that's when i thought mebbe i can use an array.
But now that you confirmed it is not possible I had to use couple of args one time and that I moved some code to run another awk script with the left over args.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.