In vim, to remove the ^M character you could do:

:e ++ff=dos

The :e ++ff=dos command tells Vim to read the file again, forcing dos file format. Vim will remove CRLF and LF-only line endings, leaving only the text of each line in the buffer.

Then set filetype to unix:

:set ff=unix

And save the file:

:x