can awk built-in "match" be exact??

hello everybody,

as explained in the title, here is what I want:

str1="name1 name2 name3"
str2="name1"
str3="name"

I know that match(str1,str2) will return 1, but I want that match(str1,str3) returns 0 (when it also returns 1...)

Is there a way to get that exact matching process done in a awk script??

cheers,
Tanguy

What do you mean by "exact"? str2 and str3 are both found in str1, but neither is an exact match.

good point otheus...

well by that I mean that I'd like to compare each "field" of str1 (all fields being separated by a coma) and test if they match str3 (exactly). So basically I want to compare name1 to name, then name2 to name, then name3 to name... and check if they are exactly the same (in which case name1 compared to name is a false)

hum... not so clear, is it?
But maybe I'm simply not doing things the easier way...

It's clear now. Can you use "nawk" or GNU awk (gawk)?

yes I can use gawk if it makes things easier

First, use the split() function to split up the "str1" into an array. Then, search the array using "==". So:

split(str1,ary,",");
for (s in ary) 
  if (s == str2 || s == str3) { found=s; break; }
print found

excellent!

I had already tried that "split" thing in a couple of less elegant ways and with no success, so many thanks for that :wink: