DelphiFAQ Home Search:

Save a text file in Unix dos style or unix style

 

comments2 comments. Current rating: 5 stars (1 votes). Leave comments and/ or 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:

2008-09-26, 10:04:29
anonymous from United Kingdom  
WARNING to other users...

With regards to

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

Please note the author does not mean the literal characters '^' followed by 'M' as this matches any character that is not a capital 'M'. Not sure why the '^M' has been wrapped with 'character set' brackets (eg. []), as it's not necessary (IMHO) and can lead to the miss understanding mentioned above. I'd suggest using the following instead

:%s/^M$//

where (as the author hinted) the '^M' is obtained using CTRL+M (or with putty CTRL+V followed by CTRL+M.

I hope this help folks.



2009-06-08, 17:14:59
[hidden] from Salem, United States  
rating
Anonymous from Morocco

OK Morocco
What point are, You trying to make by posting that copy of
what, I wrote on this thread all over this site ?
Then only speak what, I believe to be French ?
What are, You playing at ?
If, You have something to say to me then say it.
Don't play like a child and post things all over this site.
I guarantee, You will not be able to keep doing that for very long
if, You choose to keep doing it.

Agent 86 Maxwell Smart \\'^o^'//

To everyone else this Morocco idiot copied and pasted
my words from the Bill Dorsen thread.


This image was also posted here:
Dating scammer Yulia
Dating scammer Tatyana Smirnova from Molodezhnyi, Russia
Dating scammer Ekaterina from Cheboksary, Russia
Dating scammer Nancy Milman from Accra, Ghana
Dating scammer Esther Ansomaa from Accra, Ghana
Dating scammer Bill Dorsen
Dating scammer Jamila Alhassan
Dating scammer Nancy Milman from Accra, Ghana
Dating scammer Osei Kwesi Accra Ghana kind_osei@hotmail.com from Accra, Ghana
Dating scammer Josh Kelly
Dating scammer Richard Wilson
Another dating / chat scam - USA/ Nigeria connection
Primer for first time visitors (Dating Scams)
Olga Kudryavzeva alias Elena Shamova
Dating scammer Tatiana Sheglova from Kirov, Russia
Dating scammer Rhoda Naa from Accra, Ghana
Dating scam artist Sindy Becky Green in Ashley, Ohio (Lagos, Nigeria)
How much does MTS improve connect times?
Is this Russian girl scamming me? How to recognize scammers
Client / Server programming - generic steps to start a server or a client
How can I improve our production InterBase database server?
Dating scam from Kazan, Russia - Part 5
Another dating / chat scam - USA/ Nigeria connection



Keywords:

 

 

NEW: Optional: Register   Login
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, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
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.