title: Why does my tool output overwrite itself and how do I fix it?
body: <p>The intent of this question is to provide an answer to the daily questions whose answer is "you have DOS line endings" so we can simply close them as duplicates of this one without repeating the same answers <em>ad nauseam</em>.</p>
  
  <p>NOTE: <strong>This is NOT a duplicate of any existing question</strong>. The intent of this Q&amp;A is not just to provide a "run this tool" answer but also to explain the issue such that we can just point anyone with a related question here and they will find a clear explanation of why they were pointed here as well as the tool to run so solve their problem. I spent hours reading all of the existing Q&amp;A and they are all lacking in the explanation of the issue, alternative tools that can be used to solve it, and/or the pros/cons/caveats of the possible solutions. Also some of them have accepted answers that are just plain dangerous and should never be used.</p>
  
  <p>Now back to <strong>the typical question</strong> that would result in a referral here:</p>
  
  <p>I have a file containing 1 line:</p>
  
  <pre><code>what isgoingon
  </code></pre>
  
  <p>and when I print it using this awk script to reverse the order of the fields:</p>
  
  <pre><code>awk '{print $2, $1}' file
  </code></pre>
  
  <p>instead of seeing the output I expect:</p>
  
  <pre><code>isgoingon what
  </code></pre>
  
  <p>I get the field that should be at the end of the line appear at the start of the line, overwriting some text at the start of the line:</p>
  
  <pre><code> whatngon
  </code></pre>
  
  <p>or I get the output split onto 2 lines:</p>
  
  <pre><code>isgoingon
   what
  </code></pre>
  
  <p>What could the problem be and how do I fix it?</p>