title: Compare multiple text files, and save commons values
body: <p>My actual code : </p>
  
  <pre><code>import os, os.path
  
  DIR_DAT = "dat"
  DIR_OUTPUT = "output"
  filenames = []
  
  #in case if output folder doesn't exist
  if not os.path.exists(DIR_OUTPUT):
      os.makedirs(DIR_OUTPUT)
  
  #isolating empty values from differents contracts
  for roots, dir, files in os.walk(DIR_DAT):  
      for filename in files:
          filenames.append("output/" + os.path.splitext(filename)[0] + ".txt")
  
          filename_input = DIR_DAT + "/" + filename
          filename_output = DIR_OUTPUT + "/" + os.path.splitext(filename)[0] + ".txt"
  
          with open(filename_input) as infile, open(filename_output, "w") as outfile:
              for line in infile:
                  if not line.strip().split("=")[-1]:
                      outfile.write(line)
  
  #creating a single file from all contracts, nb the values are those that are actually empty
  with open(DIR_OUTPUT + "/all_agreements.txt", "w") as outfile:
      for fname in filenames:
          with open(fname) as infile:
              for line in infile:
                  outfile.write(line)
  
  #finale file with commons empty data
  #creating a single file
  with open(DIR_OUTPUT + "/all_agreements.txt") as infile, open(DIR_OUTPUT + "/results.txt", "w") as outfile:
      seen = set()
      for line in infile:
          line_lower = line.lower()
          if line_lower in seen:
              outfile.write(line)
          else:
              seen.add(line_lower)
  
  print("Psst go check in the ouptut folder ;)")
  </code></pre>
  
  <p>The last lines of my code are checking wether or not, element exists mutliple times. So, may the element exists, once, twice, three, four times. It will add it to results.txt.</p>
  
  <p>But the thing is that I want to save it into results.txt only if it exists 4 times in results.txt.</p>
  
  <p>Or best scenario, compare the 4 .txt files and save elements in commons into results.txt.</p>
  
  <p>But I can't solve it..</p>
  
  <p>Thanks for the help :)</p>
  
  <hr>
  
  <p>To make it easier, </p>
  
  <pre><code>with open(DIR_OUTPUT + "/all_agreements.txt") as infile, open(DIR_OUTPUT + "/results.txt", "w") as outfile:
      seen = set()
      for line in infile:
          if line in seen:
              outfile.write(line)
          else:
              seen.add(line)
  </code></pre>
  
  <p>Where can I use the .count() function ?
  Because I want to do something like xxx.count(line) == 4 then save it into resulsts.txt</p>