sdf
1
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
aigles
2
Something like that :
awk 'NR==FNR{x[$0];next}{for(r in x) r=r+".*" gsub(r, "",$2)}1' patternlist infile
Jean-Pierre.
sdf
3
Unfortunately it removes only the pattern string but not the rest of the line.
CarloM
4
I don't think I understand the question.
Is it the same as this?
sdf
5
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