Solved

Replace variable in awk print statement

Posted on 2004-09-16
1
1,275 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 20

Accepted Solution

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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now