awk variables
Oscar Herrera
oscarh at hpdmd48.boi.hp.com
Sat Dec 1 02:24:08 AEST 1990
>I am trying to use both shell variables and awk variables in the
>same awk call, but I cannot get both to work correctly. I have tried
>many variations of quoting and have had no success. The statement
>I want to use is :
>
> awk "NR == $line_num {print $1}" filename
>
>where $line_num is a script variable (an integer) and $1 is the
>awk variable for the first field. I would even like to get more fancy
>and say {print $n} where $n is a shell variable like "$1", "$2",...
>
>Does anyone know how this can be done in the C-Shell?
>Thanks.
>----------
try
awk 'NR == '$line_num '{print $1}' filename
Having $line_num not enclosed in single quotes should
allow the shell to get a hold of it and stick the variable value
in its place. I did not test this myself, but I vaguely
remember this from a class long ago.
More information about the Comp.unix.shell
mailing list