Shell Variables in AWK Expressions?

Don Flynn djf2@danu.ili.net
Mon, 1 Oct 2001 13:02:51 -0400 (EDT)


On Mon, 1 Oct 2001 Paul_Melson@keykertusa.com wrote:

> Here's the offending portion of the script:
> 
> loop=`wc -l column1.txt | cut -c5-7`
> pool=1
> while [ $loop -gt $pool ]; do
>         for file in 1 2 3 4 5 6 7 8
>         do
>                 echo -n `awk 'NR == $pool' column${file}.txt`,
>         done
>         echo
>         pool = `expr $pool + 1`
> done
> 
> Everything seems to work fine except for that awk statement.  All I get are
> the commas, which indicates to me that it's not reading $pool or treating
> it like a 0/null, and if I use ${pool} I get a parse error message because
> of the braces.  What's the appropriate way to pass shell variables to an
> awk expression?
> 
> Thanks,
> 
> PaulM
> 
Paul,

     What does the data in this file look like?  It might be easier to do
this all inside awk if its not scattered about randomly.  What might help
for this particular instance is :
  
echo -n `eval awk '{NR == ${pool}}' column${file}.txt`



--
"Is that sound you're hearing the trumpeting of St. Peter's angels
 or the screams of Memnoch's tortured souls?"
Don Flynn        djf2@ili.net                   Sayge@IRC