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!

is there a way to pass a variable i

Status
Not open for further replies.

PuPPeT2

Programmer
Jul 28, 2003
5
US
is there a way to pass a variable into an awk statement from out site the statement?

variable="hello world"
cat file| awk '
{
print "variable from outside awk:"variable
}'

where would we all be w/out awk, sed and grep?
 
i guess i could have asked if there was a way to reference variables from outside an awk statement in an awk statement too or perhaps instead
 
Like this

cat file| awk -v var=$variable '
{
print "variable from outside awk:" var
}'


CaKiwi

"I love mankind, it's people I can't stand" - Linus Van Pelt
 
There's a few ways. Read my FAQ ... Faq271-1281

Greg.
 
UUOC - sorry for nit-pickin'

awk -v var=$variable '{print "variable from outside awk:" var }' file

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top