Solved

Replace variable in awk print statement

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
substring method in java 1 129
Hibernate methods 2 77
abstract class with all non abstract mentods 6 79
SQUD PROXY SERVER, UNIX, SLL/HTTPS 5 103
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

809 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