Simple two file compare with twist

view full story

http://www.unix.com – I have file1 and file2 I lookup field3 from file2 in field1 of file1 and if there is a match, output field 2,3,5 from file2. I now want to add field2 of file1 in the output. I suspect what I have to do is read the entire line of file1 into a 2 dim array? pls help. here is my code: cat file1 Code: foo,cmd1 bar,cmd2 cat file2 Code: Hello,World,foo Alice,Bob,bar Egg,Spam,ham output with current awk: Code: awk -F, 'FNR==NR {arr[$1];next} $3 in arr {OFS=","; print $2,$4,$5}' file1 file2 World,fi,fom Bob,bie,doll desired output: Code: World,fi,fom,cmd1 Bob,bi (HowTos)