Computing.Net > Forums > Unix > AWK in a while loop

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

AWK in a while loop

Reply to Message Icon

Name: Big_Z
Date: January 11, 2005 at 10:04:27 Pacific
OS: AIX 5.1
CPU/Ram: RISC/1GB
Comment:

Hello, here is my issue -

I am running a script with a while loop. I have an awk statement within the while loop that uses an incremented variable. the script does not like me to use a variable in the awk statement.

Here is a snippet of the script where I am having the problem:
____________________________________
integer i=0

while (( ( i += 1 ) < $NUMTAB )) do

TABNAME=$(awk 'NR==${i}' /backup/tables.txt)
print "export_def_table DEV "$TABNAME" ~ecs/backup/"$TABNAME".exp"

done
______________________________________

This part of the loop is giving me the error:
TABNAME=$(awk 'NR==${i}' /backup/tables.txt)

It doesn't like when I use ${i} in the awk statement.

Can anyone help me with this??

Thanks!




Sponsored Link
Ads by Google

Response Number 1
Name: Jim Boothe
Date: January 11, 2005 at 11:07:08 Pacific
Reply:

Use double-quotes instead of single-quotes, and that will allow the shell to evaluate $i:

awk "NR==${i}"


0

Response Number 2
Name: vgersh99
Date: January 11, 2005 at 13:48:20 Pacific
Reply:

TABNAME=$(nawk -v i="${i}" 'NR==i' /backup/tables.txt)


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: AWK in a while loop

using arrays in a while statement ? www.computing.net/answers/unix/using-arrays-in-a-while-statement-/5003.html

problem with grep in a for loop www.computing.net/answers/unix/problem-with-grep-in-a-for-loop/3967.html

deleting rows in a file www.computing.net/answers/unix/deleting-rows-in-a-file/3676.html