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

regular expression

Status
Not open for further replies.

lambros

Programmer
Oct 10, 2002
42
US
Hi,

How do I search $0 for the value of an array?

my script uses;

reg[1] = var

then later I have;

for (i in reg)
print reg

This works fine;

how can I search $0 for this value;

can I do;

if ($0 ~ /reg/) ?
 
I assume this is awk. Your post is garbled because the
Code:
[i]
turned on italics. (uncheck the process TGML box or use j instead of i). But if I understand your post correctly, the answer is yes.

CaKiwi
 
Upon further review, I now think the answer is no. Remove the slashes.
Code:
   if ($0 ~ reg[i]) ...
CaKiwi
 
Hi CaKiwi,

I've also tried this & it works to a point, however if I elaborate on it & do

if ($0 ~ reg && /78/)

it doesn't return anything, even thought this works on the command line ( when I insert the values returned by print reg... do you know why this is?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top