-
Hi All,
Is it possible to get the value of a variable inside awk, which has a value assigned outside of the awk command.
Example:
test.ksh
----------
choice=1
export choice
awk '{..........}' infile
I want to get the value of choice inside the awk. Is it possible?
Any help is appreciated.
Thaks
Najmal
-
yes it is possible
use $choice
The script works
In GOD I find everything
-
Unix AWK
Hi,
It is not working that way.
If I give,
choice=1
export choice
awk '{print $choice}' infile
It doesn't print anything.
Please clarify how can it be done.
Thanks for you resp.
Najmal
-
This is slightly complicated
.you can try this code
export choice=1
awk '{
for ( x in ENVIRON)
if ( x ~ /choice/ )
print ENVIRON[x]}
' infile
This is more complicated than I thought
GOOD LUCK
In GOD I find everything
-
use can use the -v option when starting awk :
eg.
year=$(date +%Y)
echo test | awk -v yearstring=$year '{ print "xxx" yearstring "xxx" $1 }'
Hope this helps
Gert
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|