Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regarding variable 1

Status
Not open for further replies.

frankli

Technical User
Apr 6, 2005
44
CA
Hello all,

I have a text file(vfile) that records all the variable names, something like

#cat vfile | head -1
file1 v_name1 v_name2 v_name3

I want to display the value of the variable by querying this file, however, it seems I could not by simplying doing below, need some idea how to accomplish this. Thanks.

echo $v_name1
10.1.2.3:7000

echo $"`cat vfile | head -1 | awk '{print $2}'"
v_name1

how can I get 10.1.2.3:7000 instead of v_name1?

 
Have a look at the eval shell built-in.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Merci bien PHV,

I can get the result with

eval echo "\$`cat vfile | head -1 | awk '{print $2}'`"
10.1.2.3:7000

however, I got trouble on how to assign this value to another variable or say i want to do below

grep -i `eval echo "\$`cat vfile | head -1 | awk '{print $2}'`"` file_1

something like that, I want to use that value, I know above has syntax error, just don't know how to correct it, please comment. Thanks.
 
eval grep -i \"`awk 'NR==1{print $2;exit}' vfile`\" file_1


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
yes, it works, thanks!

eval grep -i \"\$`awk 'NR==1{print $2;exit}' vfile`\" file_1

I like the way you use awk!
 
Sorry for the typo, I meant this:
eval grep -i \"`awk 'NR==1{print "$"$2;exit}' vfile`\" file_1

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
yes, it works too. I like it.

I probably need to ask more about awk in the awk forum.

thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top