title: Reproduce the Unix cat command in Python
body: <p>I am currently reproducing the following Unix command:</p>
  
  <pre><code>cat command.info fort.13 &gt; command.fort.13
  </code></pre>
  
  <p>in Python with the following:</p>
  
  <pre><code>with open('command.fort.13', 'w') as outFile:
    with open('fort.13', 'r') as fort13, open('command.info', 'r') as com:
      for line in com.read().split('\n'):
        if line.strip() != '':
          print &gt;&gt;outFile, line
      for line in fort13.read().split('\n'):
        if line.strip() != '':
          print &gt;&gt;outFile, line
  </code></pre>
  
  <p>which works, but there has to be a better way. Any suggestions?</p>
  
  <p>Edit (2016):</p>
  
  <p>This question has started getting attention again after four years. I wrote up some thoughts in a longer Jupyter Notebook <a href="https://github.com/jbwhit/one-offs/blob/master/notebooks/2016-09-19_jbw_stackoverflow.ipynb" rel="noreferrer">here</a>. </p>
  
  <p>The crux of the issue is that my question was pertaining to the (unexpected by me) behavior of <code>readlines</code>. The answer I was aiming toward could have been better asked, and that question would have been better answered with <code>read().splitlines()</code>. </p>