^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?
Sreenadh said
Thanks guys… It helped me.
Jp said
Thanks
Brajendra said
I was really pissed off with this ^M in my file,
thanks to Scott i use
:set fileformat=unix
and it works……
zalgo said
@Scott: thanks the “:set fileformat=unix” worked for me on Ubuntu 10.04
anant said
thanx alot ..////
pcderic said
This guidance didn’t help me.
However, using “:set fileformat=unix” did.
Ehsan said
Thanks!
Sameer said
Thanks a lot….
SysAdmin said
just use dos2unix that’ll do the work
Narendra. said
Thanks.
J-Y Zhang said
Thanks a lot!
very helpful.
Umesh said
Use dos2unix command. i.e. to replace all DOS characters to Unix -
$ dos2unix file.c file.c
Indy said
^M comes from MAC files.
kgauri said
Thanks a lot…!!
Solomon Liu said
Spooled file from Oracle SQL contained ^M at the end of every line along with a carriage return. This tip removed them, which enhanced readability tremendously. Thanks!!!
Removendo o caracter ^M com o VIM | ATALIBA TEIXEIRA said
[...] vinda daqui , que estava perdida a pelo menos seis meses na tralhas [...]
Yefb said
Reblogged this on Infornética.