How to remove ^M character with VI

17 Jan, 2008  |  Posted by Danesh  |  in HowTo, Linux

This is how you remove those annoying ^M characters that show up in files previously edited on a Windows/DOS platform.

In VI,

:%s/[ctrlkey+v and ctrl-key+M]//g

actual command,

:%s/^V^M//g

Here’s a walk through video I made. My first actually :)

YouTube Preview Image
  • Digg
  • del.icio.us
  • BlinkList
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • Furl
  • Google
  • Live
  • Facebook
  • Pownce
  • TwitThis
  • E-mail this story to a friend!
Tags: , , ,

6 Responses so far | Have Your Say!

  1. Raja  |  January 17th, 2008 at 11:38 pm #

    Damn.. i was thinking of doing screencasts as well.
    Good job man. :)

    Raja - Gravatar
  2. Danny  |  January 18th, 2008 at 12:11 am #

    Thanks sir, more to come. It’s fun :D

    Danny - Gravatar
  3. ciprian  |  February 7th, 2008 at 4:33 am #

    hi, the ^M are showing for me on windows xp, i tried this command %s/^M//g but it doesn’t work, as soon as i put in the ctrl-m it says it cant find the pattern, is there some difference that i have to do to get to use this command on windows?

    ciprian - Gravatar
  4. ciprian  |  February 7th, 2008 at 4:48 am #

    i found this to work on windows xp

    %s/\r//g

    to replace all ^M with nothing in the whole file

    ciprian - Gravatar
  5. Danny  |  February 9th, 2008 at 3:42 am #

    Thanks for sharing the solution ciprian.

    Danny - Gravatar
  6. Liberta Design  |  June 29th, 2008 at 11:00 pm #

    Thanks man, very helpful.

    Liberta Design - Gravatar

Leave a Feedback

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>