title: Comparing two lists and printing select columns from each list
body: <p>I want to compare two lists and print some columns from one, and some from the other if two match. I suspect I'm close but I suppose it's better to check..</p>
  
  <p>1st file: Data.txt</p>
  
  <pre><code>101    0.123
  145    0.119
  242    0.4
  500    0.88
  </code></pre>
  
  <p>2nd File: Map.txt</p>
  
  <pre><code>red    1    99     
  blue    3    101
  rob    3    240
  ted    7    500
  </code></pre>
  
  <p>So, if I want to compare the 3rd column of file2 against the 1st of file1 and print the 1st column of file2 and all of file1, I tried <code>awk 'NR==FNR {a[$3];next}$1 in a{print$0}' file2 file1</code></p>
  
  <p>but that only prints matches in file1. I tried adding <code>x=$1</code> in the awk. i.e. <code>awk 'NR==FNR {x=$1;a[$3];next}$1 in a{print x $0} file2 file1</code> but that saves only one value of <code>$1</code> and outputs that value every line. I also tried adding $1 into <code>a[$3]</code>, which is obviously wrong thus giving zero output.</p>
  
  <p>Ideally I'd like to get this output:</p>
  
  <pre><code>blue    145    0.119
  ted    500    0.88
  </code></pre>
  
  <p>which is the 1st column of file2 and the 3rd column of file2 matched to 1st column of file1, and the rest of file1.</p>