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!

Problem with variable as RegExp

Status
Not open for further replies.

zaxxon

MIS
Dec 12, 2001
226
DE
Hi,
I am using gawk and give a variable filled with a string to awk like:

Code:
LIST="hello yes no"
for $ELE in LIST; do
   awk -v var=$ELE '
      $3 ~ var {print $3}' infile
done

Infile looks like:
Code:
112  3321   xxxxxhelloxxxx
3253 35     xxxxnoxxxx
753  3823   helloxxxxxxx
7123 430743 xxxxxyes
81   85311  xxxxxxxxhello

This way it never matches any of the patterns as it interprets it like /^hello$/ or /^yes$/ or /^no$/.
I want it to interpret it like /hello/ or /yes or /no/ so the pattern can be anywhere inside $3.

Thanks in forward.

laters
zaxxon
 
Replace this:
for $ELE in LIST; do
with this:
for ELE in $LIST; do

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hehe, sorry yes, that was just a typo. The original works. The only thing that doesn't work is what I described.

laters
zaxxon
 
I am sorry, I checked my simple example and it worked, I get all lines like /bla/... You are right. I must have another problem in the original. Thanks so far.

laters
zaxxon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top