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!

passing variables into a nawk script 1

Status
Not open for further replies.

ReeKetta

Programmer
Aug 17, 2001
3
US
Hi,

Is there a way to use nawk or grep to search a column in a data file when the column number and search string are input by the user? In other words, in this example I am searching the second column for the word Orient:

nawk '$2 ~ /Orient/ {print $0}' acmebooks

But what I'd like to do is use a variable instead of $2, and use a variable instead of Orient.

Thanks!

Ree
 
nawk -v column=${column2pass} -v value=${value2pass} '$column ~ value {print $0}' acmebooks
 
Reeketta:

Check out the FAQ on passing variables to awk, submitted by grega.

Regards,

Ed
Schaefer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top