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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to pass Unix shell variables in a awk script

Status
Not open for further replies.

TDK22

Technical User
Mar 5, 2002
11
IT
I've a ksh shell script and i need to merge it with an awk script.
Is it possible to pass variables set in the ksh script in the awk script.
If it's possible, can you say me how??

Thank you in advance for your help

bye
TDK22
 
This has been answered many times before in this forum ... have you read the previous threads??

Anyway, there are 2 ways ....

awk '{.......}' var1=$VAR1 var2=$VAR2 filename

or

nawk -v var1=$VAR1 -v var2=$VAR2 '{.........}' filename

Greg.
 
The variables are set in the BEGIN action only with the second form (-v) Jean Pierre.
 
I new to this and can be wrong but I was taught:

variable=this

awk {if('/'"$variable"'/' == $4) print $1, $2}

I just learned to pass variables to my awk scripts.

Kenny
 

could you post the results of running this, pls!

Or at least tell us if [???] it works in _your_ case.

vlad
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top