^M Appearing after importing files from Windows

The ^M is due to Windows and Unix using a different characters for newlines. Windows' newline character shows up as ^M in UNIX text editors.

You can use the dos2unix command to remove the ^M characters. Simply run

dos2unix filename > newfilename

and what you specified as “newfilename” will contain your file, without the ^M characters.

You can then safely delete the old copy of the file with the ^M's in it.

Or, you can fix it with 'vi'. (This is useful in cases where you are logged onto a system without dos2unix installed.)

  • Open the file(s) in vi
  • Type the following:
ESC :%s/CTRL-VCTRL-M//g
CTRL-V, CTRL-M are CONTROL+V and CONTROL+M
  • This will look like:
    :%s/^M//g,
  • Then just save the file and exit vi.
wiki/software/unix_systems/edit.txt · Last modified: 2008/12/02 10:40 by Tomas Ratkus