Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Replace variable in awk print statement

Posted on 2004-09-16
1
Medium Priority
?
1,328 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 21

Accepted Solution

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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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…
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 video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

610 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