Hope you guys out there can help.
I have 2 files as below:
file 1:
111,222,333,444,555,666
777,888,999,000,111,222
111,222,333,444,555,888
file 2:
666,AAA
222,BBB
888,CCC
I want to get the 6th column from file 1 (example, 666) and check in file 2 for the value in the 2nd column (AAA). Then print the file2 value (AAA) at the end of file1. Results should be as below:
result:
111,222,333,444,555,666,AAA
777,888,999,000,111,222,BBB
111,222,333,444,555,888,CCC
I already have a code for this but I found it to be slow (file1 has about a million lines while file2 has about 20,000 lines). I think there should be a faster way of doing this. See below for the code I did:
for line in `cat file2`
do
cellid=`echo $line|awk -F"," {'print $6'}`
area=`nawk -F"," -v cellid=$cellid '{if($1==cellid) print $2}' file2`
echo "$line,$area" >> result.txt
done
Hope you can help.
Thanks in advance!