title: Create Output file with multiple lines (Python)
body: <p>I have an file with a specific data I would like to pull.</p>
  
  <p>The file looks like this:</p>
  
  <pre><code>DS User ID 1  
  random garbage  
  random garbage  
  DS  N user name 1   
  random garbage  
  DS User ID 2   
  random garbage  
  random garbage  
  DS  N user name 2
  </code></pre>
  
  <p>So far I have:  </p>
  
  <pre><code>import sys  
  import re  
  f = open(sys.argv[1])
  
  strToSearch = ""
  
  for line in f:
          strToSearch += line
  
  patFinder1 = re.compile('DS\s+\d{4}|DS\s{2}\w\s{2}\w.*|DS\s{2}N', re.MULTILINE)
  
  for i in findPat1:  
      print(i)
  </code></pre>
  
  <p>My output to screen looks like this:  </p>
  
  <pre><code>DS user ID 1  
  DS  N user name 1  
  DS user ID 2  
  DS  N user name 2   
  </code></pre>
  
  <p>If I write to file using:</p>
  
  <pre><code>outfile = "test.dat"   
  FILE = open(outfile,"a")  
  FILE.writelines(line)  
  FILE.close()  
  </code></pre>
  
  <p>Everything is pushed to a single line:</p>
  
  <pre><code>DS user ID 1DS  N user name 1DS user ID 2DS  N user name 2 
  </code></pre>
  
  <p>I can live with the first scenario for the ouput.  Ideally though I would like to strip the 'DS' and 'DS N' from the output file and have it comma separated.</p>
  
  <pre><code>User ID 1,user name 1  
  User ID 2, username 2
  </code></pre>
  
  <p>Any ideas on how to get this accomplished?</p>