Artificial intelligent assistant

joining 2 files on 2 columns but at different column numbers using awk I have 2 files which has to be joined on $1,$2 of 1st file and $1,$8 of 2nd file using awk. file1: 111,123abc,eee,ttt,yyy 222,234bcd,ttt,yyy,333 file2: 111,hhhh,eeee,rere,,23,2014,123abc 222,jjkj,7878,uhjj,1,45,2013,234bcd 333,aaa,hhh,jjjj,2,78,590,567acd output: 111,123abc,hhhh,eeee,rere,,23,2014 222,234bcd,jjkj,7878,uhjj,1,45,2013

Try:


$ awk -F, -v OFS=, 'NR==FNR{a[$1,$2]=1; next} ($1,$8) in a {print $1,$8,$2,$3,$4,$5,$6,$7}' file1 file2


which gives:


111,123abc,hhh,eeee,rere,,23,2014,123abc
222,234bcd,jjkj,7878,uhjj,1,45,2013,234bcd


This isn't exactly the same as your output as you have 8 columns in the first and 9 in the second. I've assumed that's a typo :-)

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 87a0c1697140fec6b3d5a22ff4a4ab37