title: join 2 files based on fields in a columns
body: <p>I´m trying to join two files that have different row and columns length and have a column which contains similar information in an unsorted way.</p>
  
  <p>The files look like this:
  file 1</p>
  
  <pre><code>ab 23 33 4 55 6 7 8 9
  ab 2 3 44 5 6 7 8
  ab 3 4 22 7 8 9 9 00 9
  ad 2 3 4 5 4 3
  ac 456 47 8 9 0 0 hh kk
  af 2 dd 5 6 zz 7 8
  </code></pre>
  
  <p>file2</p>
  
  <pre><code>data ab 33 4 5
  data ad 3 4 5 
  data ac 3 4 5 6 7 8 
  </code></pre>
  
  <p>expected output:</p>
  
  <p>file 3</p>
  
  <pre><code>ab 23 33 4 55 6 7 8 9 data ab 33 4 5
  ab 2 3 44 5 6 7 8 data ab 33 4 5
  ab 3 4 22 7 8 9 9 00 9 data ab 33 4 5
  ad 2 3 4 5 4 3 data ad 3 4 5 
  ac 456 47 8 9 0 0 hh kk data ac 3 4 5 6 7 8
  </code></pre>
  
  <p>Looking also other posts <a href="https://stackoverflow.com/questions/18152187/how-to-join-multiple-txt-files-into-based-on-column">How to join multiple txt files into based on column?</a> <a href="https://stackoverflow.com/questions/15210503/join-on-first-column-of-two-files">Join on first column of two files</a>, I figured out that the best way is using </p>
  
  <pre><code>awk
  </code></pre>
  
  <p>I tried that:</p>
  
  <pre><code>awk -F "\t" 'NR==FNR{a[$2]=$0; next}$1 in a {print $0, a[$2]}' file2 file1 &gt; file3
  </code></pre>
  
  <p>The problem is that it prints just file1 and not file2.</p>
  
  <p>I really do not understand where my mistake is. Any suggestion?</p>
  
  <p>Thank you very much!</p>