title: End of Line Overflow in start of next line
body: <p>So I have come across an AWK script that used to be working on HP-UX but has been ported over to RHEL6.4/6.5. It does some work to create headers and trailers in a file and the main script body handles the record formatting.</p>
  
  <p>The problem I am seeing when it runs now is that the last letter from the first line flows onto the start of the next line. Then the last two letters of the second line flow into the start of the third and so on.</p>
  
  <p>This is the section of the script that deals with the record formatting:</p>
  
  <pre><code>ls_buffer=ls_buffer $0;
  while (length(ls_buffer)&gt;99) {
  if (substr(ls_buffer,65,6)=="STUFF") {
  .....do some other stuff
  } else {
  if (substr(ls_buffer,1,1)!="\x01f" &amp;&amp; substr(ls_buffer,1,1)!="^") {
      printf "%-100s\n", substr(ls_buffer,1,100);
      }
  };
  #----remove 1st 100 chars in string ls_buffer
  ls_buffer=substr(ls_buffer,100);
  }
  </code></pre>
  
  <p>To start with it looks like the file had picked up some LF,CR,FF so I removed them with gsub hex replacements further up the code but it is ending the line at 100 and then re-printing the last character at the start of the second line.</p>
  
  <p>This is some sample test output just in case it helps:</p>
  
  <pre><code>1234567890123456789012345678901    00000012345TESTS SUNDRY PAYME130               DE TESTLLAND GROUP
  P1234567890123456789012345678901    00000012345TESTS SUNDRY PAYME131               TESTS RE TESTSLIN
  NS1234567890123456789012345678901    00000012345TESTS SUNDRY PAYME132               TESTINGS MORTGAG
  GES1234567890123456789012345678901    00000012345TESTS SUNDRY PAYME937               TESTS SUNDRY PA
  </code></pre>
  
  <p>Can anyone offer any suggestions as to why this is happening? Any help would be appreciated.</p>