Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1336
  • Last Modified:

Replace variable in awk print statement

Count="2"
        while [ $Count -le $FILE_COUNT ]
        do
                File=`grep ${ENTITY}"|" $CFG_FILE | awk '{print $Count}'`
                Count=`expr $Count + 1`
        done

Problem is that I want to replace "$Count" with "$2" and so forth.
I tried setting TEST="'{print \$$Count}'"
then     File=`grep ${ENTITY}"|" $CFG_FILE | awk $TEST`

Although $TEST prints correectly, the content of $File is the entire line

The $CFG_FILE has content like this:   ABC01|     a.txt     b.txt

I want File to be equal to a.txt on the first pass
then b.txt on the 2nd pass in the while loop.

thanx.
0
RudePuppyDog
Asked:
RudePuppyDog
1 Solution
 
tfewsterCommented:
To pass shell variables into awk:
 ... |awk '{print $awkvar}' awkvar=$Count`
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now