dos2unix using vi or vim – How to remove ^M chars from a DOS file

Often I need to translate source code from dos/windows format to UNIX format, MS-DOS and WINDOWS use a <carriage return>-<line feed> combination to represent end of line char while UNIX uses only a <line feed>.

To traslate from a format to the other you can use dos2unix command, if this command is not availble in your system you can use vi to traslate from Dos to Unix.

  • Open the file with VI

# vi orig_file.txt

  •  substitute the <carriage return>-<line feed> combination with only a line feed typing the following command:

:%s/^M//g
to compose the ^M character you need to press CTRL-V -> CTRL-M

  •       Save the file with the following command

:w converted_file.txt

  •       Exit from vi

:q
Have a good day!

Posted by at March 31, 2009
Filed in category: Bash Tip & Tricks, Bugs, linux, UNIX TLC, and tagged with: , ,

One Response to dos2unix using vi or vim – How to remove ^M chars from a DOS file

  1. Pingback: xAppSoftware » dos2unix using sed - How to remove ^M chars from a DOS file

Leave a Reply

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

*


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <font color="" face="" size=""> <span style="">

Statistical data collected by Statpress SEOlution (blogcraft).