removing ^M from the end of every line

Ever had someone send a file to you in *nix and you see a ^M at the end of every line? In the Windows world, the end of line is marked by a Carriage Return (^M) and a Line Feed. *nix treats the end of line differently – it does not use the ^M. This typically happens when someone transfer a text file from Windows to *nix using binary transfer in ftp as opposed to ascii.

To remove the ^M characters at the end of all lines in vi, do this :


Note that the ^v is a CONTROL-V character and ^M is a CONTROL-Shift-M. When you type this, it will look like this:


In *nix, you can escape a control character by preceeding it with a CONTROL-V, so here we are telling vi to globally replace the ^M character with nothing.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: