Acclaimed Contributor Acclaimed Contributor
Re: how to pass shell variable value into awk scripts
Use the -v awk option. Multiple -v options are allowed to allow you to pass n options to awk.

awk -v "myvar1=${MYVAR1}" -v "mickey=Mickey Mouse" -v myvar2=${USERNAME}" -f my.awk < infile > outfile

It's getnerally a good idea to enclose the entire -v "myvar=${X}" string in double quotes to preserve whitespace. In this example, the awk variable is "myvar" and it gets assigned whatever the current value of the shell variable $X happens to be.
If it ain't broke, I can fix that.