We run an automated process which changes the data structure in a file, and it has run for about a year without any issues.  It has just started failing and I have narrowed the problem down to one of the date fields in the file.  The files before and after the problem started look identical however there is something going on.  If I try and print the file to the screen with other text it jumbles the order.  I can't find any hidden characters in the file although I suspect there must be one.  Anyone seen this before?Here is an example.  I trimmed everything out of the file other than the dodgy fields and compare an old file with a new one:$ cat old.file16-JUN-201515-JUN-2015$ cat old.file | awk '{print a $1 b}'a16-JUN-2015ba15-JUN-2015b$ for line in `cat old.file`;do echo a${line}b;donea16-JUN-2015ba15-JUN-2015b$$$ cat new.file23-JUN-201516-JUN-2015$ cat new.file | awk '{print a $1 b}'b23-JUN-2015b16-JUN-2015$ for line in `cat new.file`;do echo a${line}b;doneb23-JUN-2015b16-JUN-2015I'm runnin Red Hat EL Server.  Thanks,
Order of text jumbled when printing
terminal;special characters;data
You have somehow got Windows style line endings, ie CRLF \x0D\xOA \r\n ...printf 'xyz\r\n' >file; cat file | awk '{print a $1 b}'outputs bxyz cat file | sed -n l outputs xyz\r$ - The $ inidcates end-of line You can filter out any extrandous \rs from a \r\n pair with awkcat file | awk -vRS='\r?\n' 1 | sed -n lOutputs xyz$To correct the problem:  cat file | awk -vRS='\r?\n' 1 > file.fixedWhy this behaviour?  When the cat file output is displayed on a terminal, the \r (Carriage-Return), does what it is(was) intended to do, ie. Return the Carriage fully to the left. For the terminal, this means that the text-insertion point is moved to the left edge of the screen - the terminology and concept of \r derrives from the manual typewriter era, when the Carriage was Returned to the left margin (by a hand operated lever), and once at the left margin, the roller would advance the paper down by 1 line, ie, it Fed the paper 1 Line.   In the terminal, because you have b after \r, the b overwrites the previouly placed a in column 1. 