|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
awk print using a variable
hey, just want to ask how to do this. ex. Code:
g="hi i am john"
h=`echo $g | awk '{print $2}'`
echo $hOUTPUT is 'i' What if I want to use a variable instead of using '2', how do I do that? Because this one does not work: Code:
a=2
h=`echo $g | awk '{print ${$a}}'`this one also does not work: Code:
a=2
h=`echo $g | awk '{print $a}'`anyone? thanks! Last edited by Franklin52; 02-08-2012 at 05:19 AM.. Reason: Please use code tags for code and data samples, thank you |
| Sponsored Links | |
|
|
|
#3
|
|||
|
|||
|
cool..thanks!
|
|
#4
|
||||
|
||||
|
In shell that supports arrays (bash/ksh): Code:
g="hi i am john"
i=2
h=( $g )
echo "${h[ $((i-1)) ]}" |
| Sponsored Links | ||
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| awk print variable | zorrox | Shell Programming and Scripting | 7 | 05-07-2011 11:25 PM |
| How to print variable value using file. | bhavesh.sapra | Shell Programming and Scripting | 6 | 10-30-2009 04:24 AM |
| How to print a value in the variable using awk ? | jisha | Shell Programming and Scripting | 1 | 01-14-2008 06:45 AM |
| print the name of variable | sun-guy | Shell Programming and Scripting | 1 | 08-06-2006 05:03 PM |
| print variable in awk | kazanoova2 | Shell Programming and Scripting | 8 | 05-17-2004 06:30 PM |
|
|