title: AWK: Comparing two different columns in two files
body: <p>I have these two files</p>
  
  <p>File1: </p>
  
  <pre><code>9 8 6 8 5 2
  2 1 7 0 6 1
  3 2 3 4 4 6
  </code></pre>
  
  <p>File2: (which has over 4 million lines)</p>
  
  <pre><code>MN 1 0
  JK 2 0
  AL 3 90
  CA 4 83
  MK 5 54
  HI 6 490
  </code></pre>
  
  <p>I want to compare field 6 of file1, and compare field 2 of file 2.  If they match, then put field 3 of file2 at the end of file1
  I've looked at other solutions but I can't get it to work correctly.</p>
  
  <p>Desired output:</p>
  
  <pre><code>9 8 6 8 5 2 0
  2 1 7 0 6 1 0
  3 2 3 4 4 6 490
  </code></pre>
  
  <p>My attempt:</p>
  
  <pre><code>awk 'NR==FNR{a[$2]=$2;next}a[$6]{print $0,a[$6]}' file2 file1
  </code></pre>
  
  <p>program just hangs after that.</p>