Solved

Replace variable in awk print statement

Posted on 2004-09-16
1
1,297 Views
Last Modified: 2013-12-26
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
Comment
Question by:RudePuppyDog
1 Comment
 
LVL 21

Accepted Solution

by:
tfewster earned 100 total points
ID: 12080388
To pass shell variables into awk:
 ... |awk '{print $awkvar}' awkvar=$Count`
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question