^M is DOS line break charater which shows up in unix files when uploaded from a windows file system in ascii format.
To remove this, open your file in vi editor and type
:%s/(ctrl-v)(ctrl-m)//g
and press Enter key.
Important!! – press (Ctrl-v) (Ctrl-m) combination to enter ^M character, dont use “^” and M.
If anything goes wrong exit with q!.
I learned this from here.






L(C^2) said
Very good!
I just encountered this problem and it is so annoying to replace each ^M one by one!
Thank the god here is the solution~
rachel said
i love ram\’s!
Vijay Ladani said
How can I reverse all the text in a file using vi editor command?
bob said
freakin awsome. thank a bunch.
Scott said
Your substitution command may catch more ^M then necessary. Your file may contain valid ^M in the middle of a line of code for example. Use the following command instead to remove only those at the very end of lines:
:%s/(ctrl-v)(ctrl-m)*$//g
In some flavors of vi (e.g. RedHat), vi does it for you with:
:set fileformat=unix
j habib said
How to add ^M (Ctrl+V+M) in one particular line in an input file using script? Is it possible to store ^M in a variable?
aymeric said
the simplest way is to use the command dos2unix
swathi said
how can i remove 200c in vi editor?
Avnit said
how to do this in multiple file , is there a way we can make a program for this
srini said
Thanks a lot.. Uploaded a file from excel on to sever box with bunch of ^M
… This post help me…
Thanks
srini
pavan said
Thank you. It helped me
sab said
Thanks guys…this worked for me to remove ^M from my input file. But any idea why this comes when we ftp the a file from windows to UNIX box on ASCII mode?