|
From: rejithomas.d on 17 Apr 2008 15:04 I am getting the following error while executing this awk script. The $TMP_FILENAME has a valid string echo $TMP_FILENAME; awk ' BEGIN {while ((getline < file_name) > 0) terminal_arra y[$0] = 1 ;print $0}' file_name=$TMP_FILENAME /tmp/sshterminals awk: cmd. line:1: fatal: expression for `<' redirection has null string value Cant I pass a variable to BEGIN block and if so what am I doing wrong?? Regards Reji
From: pk on 17 Apr 2008 15:40 On Thursday 17 April 2008 21:04, rejithomas.d(a)gmail.com wrote: > > I am getting the following error while executing this awk script. The > $TMP_FILENAME has a valid string > > echo $TMP_FILENAME; awk ' BEGIN {while ((getline < file_name) > 0) > terminal_array[$0] = 1 ;print $0}' file_name=$TMP_FILENAME The above command is a bit strange. Why don't you use the -v option to assign the value to file_name? And, most important, why are you using getline? -- All the commands are tested with bash and GNU tools, so they may use nonstandard features. I try to mention when something is nonstandard (if I'm aware of that), but I may miss something. Corrections are welcome.
From: Michael Tosch on 17 Apr 2008 16:14 rejithomas.d(a)gmail.com wrote: > I am getting the following error while executing this awk script. The > $TMP_FILENAME has a valid string > > echo $TMP_FILENAME; awk ' BEGIN {while ((getline < file_name) > 0) > terminal_arra > y[$0] = 1 ;print $0}' file_name=$TMP_FILENAME > > /tmp/sshterminals > awk: cmd. line:1: fatal: expression for `<' redirection has null > string value > > > Cant I pass a variable to BEGIN block and if so what am I doing > wrong?? > > Regards > Reji > The < operator wants a "string" constant, not a variable. You loop in the BEGIN section? Did you forget that awk loops around the input in its main section? Maybe you want awk '{terminal_array[$0]=1; print}' $TMP_FILENAME -- Michael Tosch @ hp : com
From: pk on 17 Apr 2008 16:50 On Thursday 17 April 2008 22:14, Michael Tosch wrote: > The < operator wants a "string" constant, not a variable. AFAICT all that's required is that what is after the "<" evaluaes to a string, not that it must be a string constant. Actually, if you do awk -v file_name=$TMP_FILENAME ... awk does read from the file. I think the problem is that the assignment file_name=$TMP_FILENAME put at the end, after the program, is "seen" by awk only in the main program, not in the BEGIN section. -- All the commands are tested with bash and GNU tools, so they may use nonstandard features. I try to mention when something is nonstandard (if I'm aware of that), but I may miss something. Corrections are welcome.
From: Bill Marcum on 17 Apr 2008 16:35
On 2008-04-17, Michael Tosch <eedmit(a)NO.eed.SPAM.ericsson.PLS.se> wrote: > > > The < operator wants a "string" constant, not a variable. It can work with a variable, the problem is that the variable wasn't set using the -v option, so it isn't set before the BEGIN block is executed. > You loop in the BEGIN section? > Did you forget that awk loops around the input in its main section? > Maybe you want > > awk '{terminal_array[$0]=1; print}' $TMP_FILENAME > |