awk extend array for gsub()

Want to extend an array to remove the rest of the field $2. Can anybody suggest the correct code?

This code:

awk 'NR==FNR{x[$0];next}{for(r in x) gsub(r/.*/, "",$2)}1' patternlist infile

neither this works:

awk 'NR==FNR{x[$0];next}{for(r in x) r=r+"/.*/" gsub(r/.*/, "",$2)}1' patternlist infile

Something like that :

awk 'NR==FNR{x[$0];next}{for(r in x) r=r+".*" gsub(r, "",$2)}1' patternlist infile

Jean-Pierre.

Unfortunately it removes only the pattern string but not the rest of the line.

I don't think I understand the question.

Is it the same as this?

Yes it is, though since nobody answered I am trying to to solve it myself.

Try this...

awk 'NR==FNR{a[$0]++;next}{for(i in a){gsub(i,"",$0);gsub("[,.] *$","")}}1' patternlist infile

--ahamed

1 Like