bug-sed
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#26879: end-of-line issue with cygwin 4.4-1 sed 4.4


From: Eric Blake
Subject: bug#26879: end-of-line issue with cygwin 4.4-1 sed 4.4
Date: Thu, 11 May 2017 12:58:12 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.0

tag 26879 notabug
thanks

On 05/11/2017 04:23 AM, Dick Dunbar wrote:
> I've tested and searched and I can't figure this one out.

Correcting the subject line, there is no such thing as cygwin 4.4 (yet)
- cygwin is only at 2.8.0.  Individual programs are versioned
independently from cygwin1.dll.  So your report is about the Cygwin
pre-built binary of sed, where that sed version is 4.4-1.

> 
> It's a simple filename quoting filter to handle Windows files
> that contain blanks.  Easy stuff.
> 
> --- t.out ---
> C:\Scan\i .2
> 
> --- sedtest.sh ---
> #!/bin/bash
> echo "1. simple string works"
> fn="C:\Scan\i .2"
> echo " $fn"

$fn has no carriage return.

> echo $fn   | sed -e "s/^/'/" -e "s/\$/'/"

So this places the ' immediately after the 2.

> echo " "
> echo "2. against a cat file fails"
> cat t.out  | sed -e "s/^/'/" -e "s/\$/'/"

cat preserves line-endings, as does sed.  $ matches ONLY \n (not \r\n)
when in binary mode.  So you are sticking the ' in between \r and \n.
Visually, the way the terminal displays that is that it prints 2, then
rewinds to the beginning of the line, then displays ' (on top of what
was already ' that you inserted at the beginning), and then finally
moves to the next line.

> echo " "
> echo "3. against the file itself fails"
>  sed -e "s/^/'/" -e "s/\$/'/" t.out

Same story.


> 
> ==== Am I doing something wrong, or is this a bug? =====

You are forgetting that sed does NOT ignore \r on binary files.

Cygwin sed used to blindly treat binary files in text mode, but that was
INTENTIONALLY changed in February, in a coordinated move with grep and
awk at the same time.  If you fail to read cygwin release notes, it's
your own fault for being caught off-guard when you do a blind update:
https://cygwin.com/ml/cygwin-announce/2017-02/msg00036.html

Cygwin's goal is to emulate Linux, and Linux has the same behavior (of
NOT ignoring \r by default).  If you want to ignore \r, then explicitly
do so, either by massaging your data, using something like:
 d2u file | sed ...
 tr -d '\r' < file | sed ...
Or, you can use a text-mode mount instead of a binary-mode mount for
hosting file (the cygwin list is a better resource for how to set up a
text-mode mount point).

As such, I'm closing this as not an upstream bug.  If you don't like the
intentional change in cygwin behavior, that's something you may want to
bring up on the cygwin list, but there's nothing we can do about it here.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]