source: tech-recipes
To remove the carriage-return character from a windows originating file in vi:
:%s/<Ctrl-V><Ctrl-M>/g
or
:%s/\r//g
In UNIX, you can escape a control character by preceeding it with a CONTROL-V. The :%s is a basic search and replace command in vi. It tells vi to replace the regular expression between the first and second slashes (^M) with the text between the second and third slashes (nothing in this case). The g at the end directs vi to search and replace globally (all occurrences).