Shell Variables in AWK Expressions?

Paul_Melson@keykertusa.com Paul_Melson@keykertusa.com
Mon, 1 Oct 2001 11:57:13 -0400


I'm trying to write a cheesy parsing script for NetBackup for UNIX log
files that will read the file and create comma-delimited output with the
information I want.

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