delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/10/18/06:12:20

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
From: "Dave Korn" <dave DOT korn AT artimi DOT com>
To: <cygwin AT cygwin DOT com>
References: <AB5E58B87EB73C46A38073D8F459F11335B8D2 AT dataspheresrv01> <4716E9E2 DOT 9030509 AT cwilson DOT fastmail DOT fm>
Subject: RE: Problem with the dos2unix command
Date: Thu, 18 Oct 2007 11:11:54 +0100
Message-ID: <051c01c8116f$505021d0$2e08a8c0@CAM.ARTIMI.COM>
MIME-Version: 1.0
X-Mailer: Microsoft Office Outlook 11
In-Reply-To: <4716E9E2.9030509@cwilson.fastmail.fm>
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

On 18 October 2007 06:07, Charles Wilson wrote:

> Patrick Monnerat wrote:
>>     I'm trying to convert a \r\n line-ending file to unix style, but
>> this file has some lines with their last character being \r (i.e.: the
>> sequence of binary bytes is ...\r\r\n...)
>> 
>> Using dos2unix to convert it strips both \r, resulting in a byte sequence
>> ...\n... 
>> 
>> This seems to me a bug. I need the trailing \r in the file as a normal
>> character, not being part of the line ending.
> 
> This behavior is by design.  What you ask doesn't make much sense for
> most text processing:

  But, since it's what Patrick wants:

sed -b -e 's/\r$//g' < infile > outfile

ought to do the trick:

/artimi/chips $ od -c foo
0000000   l  \r   i   n   e       1  \r  \n   l   i   n   e   s       2
0000020  \r  \r  \n   l   i   n   e   s       3  \r  \n
0000034
@_______. .
(       /"\
 ||--||(___)
 '"  '"'---'
/artimi/chips $ sed < foo -b -e 's/\r$//g' | od -c
0000000   l  \r   i   n   e       1  \n   l   i   n   e   s       2  \r
0000020  \n   l   i   n   e   s       3  \n
0000031
@_______. .
(       /"\
 ||--||(___)
 '"  '"'---'
/artimi/chips $

    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019