title: Using bash script to compare two files and write new file
body: <p>I am new to bash scripting and would like to write a bash script to do the following.
  I have two tab delimited files as follows:</p>
  
  <pre><code># file1 #
  ## position id 
  .
  .
  .
  
  
  # file2
  ## position type
  . 
  .
  .
  </code></pre>
  
  <p>file 2 is a subset of file 1 with regard to the position column. 
  I want to generate file3 such that for every line in file2, it looks up the line with the same position in file1 and writes out the following into file3</p>
  
  <pre><code>position id type
  .
  .
  .
  </code></pre>
  
  <p>So, I want to essentially find the common positions between file1 and file2 (first column) and write them out along with their id and types (column 2 in the respective files).
  I know how to do this using python but I would like to learn how to do a procedure like this using a bash script - i would appreciate any example code for the above problem.</p>
  
  <blockquote>
    <p>Extra note: </p>
  </blockquote>
  
  <p>The values in each column are as follows </p>
  
  <ul>
  <li>position: chr1:887799</li>
  <li>id: R2A</li>
  <li>type: analphabeticstring</li>
  </ul>
  
  <p>Thanks</p>