title: Trying to update text file records in place and write them out to an output file
body: <p>I read an input file and try to reformat the date field where it is not fully formed by replacing single digit 'day' values in the date with two digit 'day' values. Appeared to work well at first then I noticed that the input file had (279) records but the output was written with (615) records. Many, if not all, of the single digit day values were replaced as expected but the original versions of those records seemed to have been written out as well to the output. Of course the expectation was that the output would have (239) records as well ??? (The script runs without throwing any errors).</p>
  <pre><code>replacements = {'/1':'/01', '9/':'09/', '7/':'07/'}
  file2 = open(r&quot;c:\users\liddvdp\desktop\IBC CAP OUT.txt&quot;, &quot;w&quot;)
  with open(r&quot;c:\users\liddvdp\desktop\IBC CAP.txt&quot;, &quot;r&quot;) as reader:
           for line in reader:
               for src, target in replacements.items():
                   line = line.replace(src, target)
                   file2.write(line)
  </code></pre>