Most probably, your text file was created on a Macintosh or a Windows PC. On these machines, different codes for the end-of-line (EOL) character are used: UNIX uses a linefeed (LF or Control-J or ASCII 012), the Macintosh uses a carriage return (CR or Control-M or ASCII 015). To be incompatible with both, Microsoft uses the combination CRLF. To get rid of the CR characters, do the following:

If the CR (^M) characters occur at the end of the lines, the file was created on an IBM compatible PC. In that case, just delete them with the command

tr -d '\r' < file1.tex > file2.tex

If the whole text appears to be on one long line with CR’s scattered over it, the file stems from a Macintosh. You have to replace the CR’s with LF’s as follows:

tr '\r' '\n' < file1.tex > file2.tex

In both cases, file1.tex stands for the original, and file2.tex for the modified file having the correct, UNIX line endings.

In case you are forced to create a file with Microsoft line endings from a UNIX text file, this command will help you out:

sed -e 's/$/\r/' file1.tex > file2.tex