How can I remove DOS linebreaks (^M) from my files?

Oh, the dreaded ^M - these usually occur when uploading files from a windows system, using ascii mode.  Some Windows editors may add the character to the end of each line as well during editing.

Sometimes, it's hard to even find them.  One pretty foolproof way on a Linux / Unix system is to use cat:

cat -e [filename]

This will show you lines with a $ at the end, and ^M's should show up, if they are there.  Here are a few options to remove them:

Method 1:

Method 2: Using sed

Method 3: