Sometimes when editing files in both Windows and UNIX environments, a CTRL-M character is added at the end of each line displayed as ^M in vi.Sometime this happens as well when files from a windows box were copied over to a unix/linux box using ftp (as binary).
To fix this:
In Vi, open the file then go to command mode
:%s/^V^M//g
Note: pressing ctrl v followed by ctrl m would display ^M
In sed, from the command line:
sed 's/^M//' file_with_^M.txt > clean_file.txt
Note: in bash/tcsh, press ctrl v then ctrl m