passing nawk multiple variables using -v

July 5, 2011 at 11:52:01
Specs: Windows XP
I'm trying to pass nawk 4 variables from the Korn Shell script using -v. Nawk appears to only allow me to pass up to 2 variables. Here's my nawk code:

nawk -v month="${month}" -v year="${next_yr}" -v wkofmo="${wkofmo}" -v dayofwk="${dayofwk}"
' -lines of code- '

I get a long messy error when I run the Korn Shell script that contains this nawk. It works fine if I only have 2 input varialbes.

Thanks, Lou


See More: passing nawk multiple variables using -v

Report •

#1
July 5, 2011 at 13:47:50
First, I think you will get a syntax error listing the arguments out before the body of the awk script.

Second, I have always had trouble using the -v switch with nawk. Not including the -v switch should work:

#!/bin/ksh

month=3
next_yr=2011
wkofmo=3
dayofwk=4

nawk ' {
print month
print year
print wkofmo
print dayofwk
} ' month="${month}" year="${next_yr}" wkofmo="${wkofmo}" dayofwk="${dayofwk}" mydatafile

where mydatafile is the file that nawk processes.


Report •
Related Solutions


Ask Question