Remove DOS Carriage Returns from a file

Files that are created in Microsoft Windows have a ^M at the end of a line.

There are two ways to remove them from a file.

  1. Use the dos2unix command
    dos2unix filename
  2. Use vi to change the file format
    :%s/^M//g
    or
    :set ff=unix