Often I would edit a file on my local machine using applications such as Dreamweaver or Excel. When I read these files in a UNIX terminal, the newlines are not displayed and instead are replaced with ^M characters. This makes the file appear convoluted and virtually unreadable. Here’s a fix to convert those ^M characters back to the newline characters so that the files display correctly.

Open the file in vi and type the command
:s/\r/\r/g

This performs a global search and replace through the file, replacing \r characters with \r. I don’t know why this works, but it does!

Note: You can change your settings in Dreamweaver so that newline chars are saved for UNIX format. Go to Preferences > Code Format and select Line Break Type to LF (Unix). This eliminates the problem at the source for Dreamweaver files. I have not yet discovered a solution for Excel files, so the vi workaround works well for those.