5 Ways To Remove The ^M Character At The End Of Text Files

The Windows text editors place ^M at the end of each line, which is the visual representation for 0x0D, while Unix based systems place 0x0A, in text files.

1. To remove the ^M character, in ViM, write the following in the command mode and press :w to save the changes:

:set fileformat=unix

2. Or, type this script in ViM, in the command mode and type :w to save the changes:

:1,$s/^V^M//g

3. With sed:

$ sed 's/^M//g' filename > newfilename

4. With Dos2Unix:

$ dos2unix filename newfilename

5. With col:

$ cat filename | col -b > newfilename

Liked it? Take a second to support Geekster on Patreon!
Tagged with: , , , , , ,
Posted in The Linux and Unix Articles!
One comment on “5 Ways To Remove The ^M Character At The End Of Text Files
  1. Christopher says:

    another way is to edit the file using webmin file manager and un-select (windows newlines)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Support LinuxG via Patreon
Support LinuxG.net on Patreon!
Subscribe

  

Subscribe to get the latest Linux news and how to guides directly on your e-mail!