I have 2 files which has to be joined on $1,$2 of 1st file and $1,$8 of 2nd file using awk.Can anyone please provide the solution for this as this is an urgent requirement. Thanks in Advancefile1:111,123abc,eee,ttt,yyy222,234bcd,ttt,yyy,333file2: 111,hhhh,eeee,rere,,23,2014,123abc222,jjkj,7878,uhjj,1,45,2013,234bcd333,aaa,hhh,jjjj,2,78,590,567acdoutput:111,123abc,hhhh,eeee,rere,,23,2014222,234bcd,jjkj,7878,uhjj,1,45,2013
joining 2 files on 2 columns but at different column numbers using awk
awk
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 file2which gives:111,123abc,hhh,eeee,rere,,23,2014,123abc222,234bcd,jjkj,7878,uhjj,1,45,2013,234bcdThis 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 :-)