DelphiFAQ Home Search:

Save a text file in Unix dos style or unix style

 

commentsThis article has not been rated yet. After reading, feel free to leave comments and rate it.

Question:

I've got a DOS style text file on my Linux box, when I open it in vi and save it, vi reports 'saved (dos)'. How can I make vi save it in unix style?

Answer:

VI automatically detects the format of a text file (DOS, Unix, Mac) and it tells that at the command line. To change the format use the :set fileformat= command and write the file then as shown below. If you have multiple control-Ms at the end of a line that you want to be removed, try the search and replace command (see below).

// Change from <CR><LF> (DOS) to just <LF> (Unix):
:set fileformat=unix 
:w 
 
// change back to Carriage Return + Line Feed for DOS
:set fileformat=dos 
:w 
 
// writing for apple computers:
:set fileformat=mac 
:w

// remove multiple (repeated) Carriage Returns using search and replace	
:%s/[^M]$//
:w

Comments:

 

 

Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option.
 
It seems that you are
from Washington, US .

Info/ Feedback on this

Show city and country
Show country only
Hide my location
Leave your comment here:
Please type in the code:
photo Add a picture:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity. The owner of this web site reserves the right to delete such material.