[ale] Carriage returns and line feeds

Lightner, Jeff JLightner at dsservices.com
Mon Mar 2 09:10:43 EST 2015


+1 on dos2unix (and unix2dos).   

Typically I find this question being asked when doing file transfers from UNIX/Linux to DOS/Windows because the latter expects a carriage return (^M) on each line where the former does not.   

I've never seen a need to remove line feed from each line.  As a previous poster mentioned there would be no way to determine what the line separators are if you did that.

You can preserve the original by doing something like "cat <filename> | unix2dos > new filename

You can see the special characters in a file by typing "cat -vt <filename>".   If you did the above you could compare what that command gives you for both files.

The syntax for vim below is based on calling sed options from within vim so you could do it from command line with sed.


-----Original Message-----
From: ale-bounces at ale.org [mailto:ale-bounces at ale.org] On Behalf Of DJ-Pfulio
Sent: Monday, March 02, 2015 6:18 AM
To: ale at ale.org
Subject: Re: [ale] Carriage returns and line feeds

Figured this had to be a joke - actually had a tear from the laughter.

If this is serious, David's answer works for vim ... but it is typed as "cntl-v{enter}" to get "^V^M" into the substitute command.  That's a lowercase-"v".  Probably helpful to force vim in binary mode too .... vim -b filename.

Or there is a utility - dos2unix ... if you want the opposite, there is a unix2dos util too. These are probably easier for most people. They are filters, so redirect the output to a new file, if you want to save it.


On 03/02/2015 12:06 AM, David Ritchie wrote:
> Well, LF "\n" always means end of line in a linux text file. vi/vim 
> simply ignores CRs...
> 
> Perhaps this will work for you in vim:
> 
> :%s/.$//  (delete the CR at the end of each line)
> 
>    or :%s/^V^M//g
> 
> which says find all cntl-M (CR's) in a line and replace with a null 
> strings
> 
> Note the the ^V is a control-V that will tell the command to except a 
> control character as part of a pattern.
> 
> -- David
> 
> 
> 
> On Sun, Mar 1, 2015 at 11:37 PM, Alex Carver 
> <agcarver+ale at acarver.net>
> wrote:
> 
>> How do you propose to mark the end of a line when \r\n is the end of 
>> the line?
>>
>> On 2015-03-01 20:26, Terry wrote:
>>> Is there a way to remove all the \r\n embedded in a txt file except 
>>> the
>> ones at the end of each line?
>>>
>>> Thanks,
>>>
_______________________________________________
Ale mailing list
Ale at ale.org
http://mail.ale.org/mailman/listinfo/ale
See JOBS, ANNOUNCE and SCHOOLS lists at
http://mail.ale.org/mailman/listinfo



More information about the Ale mailing list