title: Comparing two files and printing similar lines
body: <p>I've got two text files which both have index lines. I want to compare <a href="https://gist.github.com/bodieskate/5610191" rel="nofollow">file1</a> and <a href="https://gist.github.com/bodieskate/5610199" rel="nofollow">file2</a> and send the similar lines to a new text file. I've been googling this for awhile now and have been trying grep in various forms but I feel I'm getting in over my head. What I'd like ultimately is to see the 'Mon-######' from file2 that appear in file1 and print the lines from file1 which correspond.</p>
  
  <p>(The files are much larger, I cut them down for brevity's sake)</p>
  
  <p>For even greater clarity:</p>
  
  <p>file1 has entries of the form:</p>
  
  <pre><code>Mon-000101  100.27242   9.608597   11.082   10.034
  Mon-000102  100.18012   9.520860   12.296   12.223
  </code></pre>
  
  <p>file2 has entries of the form:</p>
  
  <pre><code>Mon-000101
  Mon-000171
  </code></pre>
  
  <p>So, if the identifier (Mon-000101 for instance) from file2 is listed in file1 I want the entire line that begins with Mon-000101 printed into a separate file. If it isn't listed in file2 it can be discarded.</p>
  
  <p>So if the files were only as large as the above files the newly produced file would have the single entry of</p>
  
  <pre><code>Mon-000101  100.27242   9.608597   11.082   10.034
  </code></pre>
  
  <p>because that's the only one common to the both.</p>