STOP: WP_HEAD -->

How to remove ^M characters using VI

This is a quick tip for Linux/UNIX users who are familiar with the vi editor.

Here’s how to remove those annoying ^M characters, that show up at the end of lines, in files that were created or modified in DOS/Windows.

Open the file using vi, and type:

:%s/[CTRL+v][CTRL+m]//g

The [CTRL+v][CTRL+m] means holding down the CTRL key and then typing vm. The text displayed will look like this:

:%s/^M//g

Explanation

In Linux or UNIX, typing [CTRL+v] allows you to escape a control character.

The :%s is the substitute (search and replace) command for vi. It tells vi to replace the regular expression between the first and second slashes (^M), with the text between the second and third slashes (nothing in this case).

The g at the end tells vi to search and replace globally (i.e. all occurrences).

Tags: , , , , , , , ,

  1. Kanishq

    Concise and to the point.
    Thanks

  2. Sunny

    Thanks,
    It works for me

  3. Kev

    Awesome post!!!!

    I wish other people would be as clear and thorough as you!

Add a Comment