Monday, August 1, 2011

Removing ^M Characters from File with vi

So, I transferred a file from Windows to a Unix server, and when I opened the file with vi (not vim) on my server, I was confronted with endless ^M characters.

How do I get rid of these characters?

Basically, after some fumbling around on the internet, I determined that I needed to use the following command.

:1,$s/^M//g

To type the ^M character, press Ctrl+V for the ^ and then Ctrl+M to get the M afterward. vi apparently does not recognize the ranged specified by %, so I had to use 1,$ instead.