GNU bug report logs - #30336
sed

Previous Next

Package: sed;

Reported by: Roger Adair <adair <at> adinet.com.uy>

Date: Sat, 3 Feb 2018 17:30:01 UTC

Severity: normal

Done: Assaf Gordon <assafgordon <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 30336 in the body.
You can then email your comments to 30336 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-sed <at> gnu.org:
bug#30336; Package sed. (Sat, 03 Feb 2018 17:30:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Roger Adair <adair <at> adinet.com.uy>:
New bug report received and forwarded. Copy sent to bug-sed <at> gnu.org. (Sat, 03 Feb 2018 17:30:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Roger Adair <adair <at> adinet.com.uy>
To: bug-sed <at> gnu.org
Subject: sed
Date: Sat, 3 Feb 2018 13:11:04 -0300
Hi,

I'm using Linux Mint 18.3 with sed version

sed (GNU sed) 4.2.2

when I execute the following command:

$ sed 's/c$/7/g' test.data.asc

where the contents of test.data.asc is:

abc  abc
123456

I get the following output:

abc  abc
123456

Whereas I would expect the following:

abc  ab7
123456

If I leave the $ out of the command "ab7 ab7" appears.

What am I doing wrong?  Many thanks for reading my email.

Roger





Information forwarded to bug-sed <at> gnu.org:
bug#30336; Package sed. (Sat, 03 Feb 2018 19:25:01 GMT) Full text and rfc822 format available.

Message #8 received at 30336 <at> debbugs.gnu.org (full text, mbox):

From: Assaf Gordon <assafgordon <at> gmail.com>
To: Roger Adair <adair <at> adinet.com.uy>, 30336 <at> debbugs.gnu.org
Subject: Re: bug#30336: sed
Date: Sat, 3 Feb 2018 12:24:35 -0700
Hello,

On 2018-02-03 09:11 AM, Roger Adair wrote:
> when I execute the following command:
> 
> $ sed 's/c$/7/g' test.data.asc
> 
> where the contents of test.data.asc is:
> 
> abc  abc
> 123456
> 
> I get the following output:
> 
> abc  abc
> 123456
> 
> Whereas I would expect the following:
> 
> abc  ab7
> 123456
> 
> If I leave the $ out of the command "ab7 ab7" appears.
> 
> What am I doing wrong?  Many thanks for reading my email.

My immediate guess would be that the file has dos/mac line endings
(e.g. CRLF "\r\n" instead of just line-feed "\n").

You can test it by using 'file', like so:

  $ file test.data.sac
  test.data.asc: ASCII text, with CRLF line terminators

Or by printing it's content like so:

  $ od -tcz test.data.asc
  0000000   a   b   c       a   b   c  \r  \n      >abc  abc..<


If you see only "\r" in the output - the file has MAC line-endings.
If you see both "\r\n" - the file has dos/windows line endings.

In unix, GNU sed "$" only matches "\n", and "\r" is just another character.


Some ways to work-around it:
1. Use "dos2unix" or "mac2unix" on the file (simplest and recommend).

2. Use the following to strip "\r" from the file
(assuming it also has "\n"):

    cat test.data.asc \
        | tr -d '\r' \
        | sed 's/c$/7/g'

If the file has only "\r", convert them to "\n":

    cat test.data.asc \
        | tr '\r' '\n' \
        | sed 's/c$/7/g'


3. Add sed command to remove "\r" before doing the
other substitution:

   sed -e 's/\r$//g' -e 's/c$/7/g' test.data.asc

4. Or modify the regex itself to optionally match "\r":

   sed 's/c\r*$/7/g' test.data.asc

---

If none of the above work, and you suspect another problem,
please provide a small fragment of your input file so we can reproduce 
the issue.

regards,
 - assaf






Reply sent to Assaf Gordon <assafgordon <at> gmail.com>:
You have taken responsibility. (Mon, 05 Feb 2018 01:18:02 GMT) Full text and rfc822 format available.

Notification sent to Roger Adair <adair <at> adinet.com.uy>:
bug acknowledged by developer. (Mon, 05 Feb 2018 01:18:02 GMT) Full text and rfc822 format available.

Message #13 received at 30336-done <at> debbugs.gnu.org (full text, mbox):

From: Assaf Gordon <assafgordon <at> gmail.com>
To: Roger Adair <adair <at> adinet.com.uy>, 30336-done <at> debbugs.gnu.org
Subject: Re: bug#30336: sed
Date: Sun, 4 Feb 2018 18:17:13 -0700
On 2018-02-03 12:24 PM, Assaf Gordon wrote:
> On 2018-02-03 09:11 AM, Roger Adair wrote:
>> when I execute the following command:
>>
>> $ sed 's/c$/7/g' test.data.asc
>> [...]
> My immediate guess would be that the file has dos/mac line endings
> (e.g. CRLF "\r\n" instead of just line-feed "\n").


Confirmed off-list this is the issue - I'm thus closing this bug.

regards,
 - assaf





bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 05 Mar 2018 12:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 7 years and 106 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.