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

AWK: setting search value from a variable 1

Status
Not open for further replies.

cptk

Technical User
Mar 18, 2003
305
US
I want to do something like this ...

awk 'BEGIN {sv="dog";print sv}/$sv/...

but I can't seem to find the right syntax to use between the search slashes to apply a variable.
 
awk 'BEGIN {sv="dog";print sv}$0~sv{...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks again ... I owe you a star!

So basically what it's doing is reading the entire line (i.e. - $0), then matching (i.e. - "~") on the variable "sv" ...

So my approach to use the variable "sv" between the regular expression search slashes (e.g. /sv/ ) was way off. You can't use variables between the slashes? The slashes are used only for regular expresion searches?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top