title: Subset rows of file 2 based on common values of single column in file 1 UNIX
body: <p>I'm dealing with large files where I would like to extract only the rows where the values of one column are contained in the values of a column of another file.</p>
  
  <p>For example, in file1 I have 10,000 rows that look something like this:</p>
  
  <pre><code>Chr13998356 T   C
  Chr1401532  A   G
  Chr14021851 A   T
  </code></pre>
  
  <p>And I have in file2 (100,000+ rows) where I want only the rows where a values in column 1 in present in column 1 of file 1. So for file 2 I have:</p>
  
  <pre><code>Chr1    401530  G   G   60  0   60  11
  Chr1    401531  A   A   60  0   60  11
  Chr1    401532  A   G   30  170 60  11
  </code></pre>
  
  <p>I would like to end up with a third file with:</p>
  
  <pre><code>Chr1    401532  A   G   30  170 60  11
  </code></pre>
  
  <p>This file could have anywhere between few to 10,000 lines.</p>
  
  <p>In R, i would use something like <code>df3 &lt;- df2[df2[,1] %in% df1[,2],]</code>, but the files are too large. </p>
  
  <p>Is there a simple UNIX solution? Something like using comm, but only matching the first column instead of the whole line would be perfect. Or something with grep, but searching for 10K patterns at the same time.</p>
  
  <p>Any ideas?</p>