Path: utzoo!attcan!uunet!kddlab!trl!rdmei!ptimtc!olivea!apple!usc!sdd.hp.com!hplabs!hpl-opus!hpcc05!hpdmd48!oscarh From: oscarh@hpdmd48.boi.hp.com (Oscar Herrera) Newsgroups: comp.unix.shell Subject: Re: awk variables Message-ID: <8720009@hpdmd48.boi.hp.com> Date: 30 Nov 90 15:24:08 GMT References: <30404@boulder.Colorado.EDU> Organization: Hewlett Packard - Boise, ID Lines: 23 >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.