Optimal way to replace characters in large string with Python?
<p>I'm dealing with cleaning relatively large (30ish lines) blocks of text.  Here's an excerpt:</p>

<blockquote>
  <p>PID|1||06225401^^^PA0^MR||PATIENT^FAKE
  R|||F </p>
  
  <p>PV1|1|I|||||025631^DoctorZ^^^^^^^PA0^^^^DRH|DRH||||...</p>
  
  <p>ORC|RE||CYT-09-06645^AP||||||200912110333|INTERFACE07</p>
  
  <p>OBR|1||CYT09-06645|8104^^L|||20090602|||||||200906030000[conditio...</p>
  
  <p>OBX|1|TX|8104|1|SOURCE OF
  SPECIMEN:[source]||||||F|||200912110333|CYT
  ...</p>
</blockquote>

<p>I currently have a script that takes out illegal characters or terms.  Here's an example.</p>

<pre><code>    infile = open(thisFile,'r')
    m = infile.read()

    #remove junk headers
    m = m.replace("4þPATHþ", "")
    m = m.replace("10þALLþ", "")
</code></pre>

<p>My goal is to modify this script so that I can add 4 digits to the end of one of the fields.  In specific, the date field ("20090602") in the OBR line.  The finished script will be able to work with any file that follows this same format.  Is this possible with the way I currently handle the file input or do I have to use some different logic?</p>
