title: Compare and delete lines based on first x character match (between two files)
body: <p>I have two text files in the CWD, a.txt, and b.txt. <strong>From a.txt</strong>, I would like to <strong>delete all lines whose first 5 characters are NOT present in b.txt</strong> as any lines' first 5 characters.  (Or, saying otherwise, keep only those lines in a.txt, whose first 5 characters is present in b.txt as any lines' first 5 characters.) Content after the 5th character to the end of the line is irrelevant.</p>
  
  <p>For example:
  <strong>a.txt</strong></p>
  
  <pre><code>abcde000
  0123456xxx
  xyzxyzxyz
  kkkkkkkkkkk
  </code></pre>
  
  <p><strong>b.txt</strong></p>
  
  <pre><code>012345aabbcc
  kkkkkkkhhkkvv
  nnnnnnnnnnn
  </code></pre>
  
  <p><strong>result</strong> (lines in a.txt whose 1-5 character is present in b.txt):</p>
  
  <pre><code>0123456xxx
  kkkkkkkkkkk
  </code></pre>
  
  <p><strong>Script in progress</strong> (I am stuck how to search for exact matches withing the first 5 characters):</p>
  
  <pre><code>with open('a.txt', 'r') as file1:
      with open('b.txt', 'r') as file2:
          same = set(file1).intersection(file2)
  
          file1[0][4]
          file1[0][4]
  
  same.discard('\n')
  
  with open('same_start.txt', 'w') as file_out:
      for line in same:
          file_out.write(line)
  </code></pre>
  
  <p>Any suggestions?</p>