title: Python: Search a text file and then output specific data
body: <p>I have a set of text files that I am trying to sort and get an output from. The idea is this: I have two files containing slightly matching data, e.g.</p>
  
  <pre><code>File 1:
  000892834     13.663      0.098      0.871      0.093      0.745      4.611       4795
  
  File 2:
  892834  4916   75   37  4857 130 128  4795  4.61 -0.09    0 0
  </code></pre>
  
  <p>The main factor in matching both is the first number which is an ID number that does not change in either file save for the 000 in the front of file 1. I need to search both files, extract the rows that match that ID and output the results to a text file in which I can display the results side-by-side, such as:</p>
  
  <pre><code>output:
  000892834     13.663      0.098      0.871      0.093      0.745      4.611       4795
  892834  4916   75   37
  </code></pre>
  
  <p>The second part of the above output is not a typo, I also need the script to remove the parts after the fourth data point in file 2 for each row. I have been debating whether I should make these two files into lists first then go through them that way with list comprehension or whether it would be better to use something like a csv reader. Thanks for any help you can give. </p>
  
  <p>EDIT:
  1)The values in both lists (ID numbers) are not all the same, list 2 has different ID's and so does list 1. 
  2)Also, I need to filter out entire rows of data if certain parts do not meet a criteria, for example if column 2 in a certain row does not meet a requirement, then that line is disregarded.
  3) Also, I just found out that I need to omit any ID's that are not in both file1 and file2, so if an ID such as the one above that matches is present, then it needs to be included, otherwise it must be left out of the final text file.</p>
  
  <p>example:</p>
  
  <pre><code>for mergedData[(a, b, c), (e, f, g), .....]: 
      if mergedData[(a, e, (all first sub-indices))] &gt; 15
          &lt;delete the entire line from the .txt file&gt; and/or &lt;create a new text file containing only lines that meet the criteria&gt;
  </code></pre>