Converting EOL from Unix to DOS

From IdeaNet
Jump to: navigation, search

to change from UNIX to DOS

  • with VIM
   user@host:~$ vim unix_file
   :set fileformat=dos
   :w dos_file
  • with Sed
   user@host:~$ sed "s/$/^M/" unix_file > dos_file
Note : ^M must be typed with the following key strokes : CTRL-V CTRL-M
  • with the following command from the tofrodos package
   user@host:~$ unix2dos unix_file
you can use VIM to check the presence of the ^M characters
   user@host:~$ vim -b dos_file

from DOS to UNIX

  • with VIM
   user@host:~$ vim dos_file

or

   user@host:~$ vim -b dos_file

if the ^M characters are not displayed, do the following:

   :set fileformat=unix
   :w unix_file

if the ^M characters are displayed, do the following:

   :%s/^M$//g
   :w unix_file
Note : ^M must be typed with the following key strokes : CTRL-V CTRL-M
  • with Sed
   user@host:~$ sed "s/^M$//" dos_file > unix_file
Note : ^M must be typed with the following key strokes : CTRL-V CTRL-M
  • with the following command from the tofrodos package
   user@host:~$ dos2unix dos_file
you can use VIM to check the ^M characters have been removed
   user@host:~$ vim -b unix_file