In stead of focussing how to remove the ^M, I'd look into
how the ^M got there in the first place, and eliminate that.
One way of ^M appearing is if you transfer files from a Unix
platform to a DOS (or Windows) platform using FTP in ASCII
mode. This is usually what you want though. Transferring in
binary mode makes that FTP leaves your file as is.
What also might happen is that you transfer file from Windows
to Unix using FTP in binary mode, but you never noticed the
^M on Windows, because, hey, that's the way it works out there. Then the solution is to transfer files in FTP ASCII
mode.
Abigail