Remove the ^M from config files

Working in both Windows and Linux environments can from time to time create undesirable effects when modifying Linux configuration files on Windows boxes.

After the edits and copying the file to the Linux box, a quick check of the file using the cat revealed nothing out of the ordinary.  However, the vim revealed the hidden ^M.

I’m still not entirely certain what that means, but it annoyed me.

One approach is to download and use the dos2unix command against the file. Using the -k preserves the date. Using man dos2unix will reveal more tips and tricks.

yum install dos2unix
dos2unix -k myconfigfile

As if that were not enough. I have found this neat sed trick.

sed -i.bak 's/^M$//' infile.txt

To type ^M, you need to type CTRL-V and then CTRL-M.

Source(s)
http://stackoverflow.com/questions/13589895/shell-command-to-strip-out-m-characters-from-text-file?noredirect=1&lq=1