GNU bug report logs - #27354
strange behavior of sed

Previous Next

Package: sed;

Reported by: Han Lu <luhanwa <at> gmail.com>

Date: Wed, 14 Jun 2017 04:10:02 UTC

Severity: normal

Tags: notabug

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

Bug is archived. No further changes may be made.

Full log


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

From: Assaf Gordon <assafgordon <at> gmail.com>
To: Han Lu <luhanwa <at> gmail.com>
Cc: 27354-done <at> debbugs.gnu.org
Subject: Re: bug#27354: strange behavior of sed
Date: Wed, 21 Jun 2017 20:18:59 +0000
Hello,

On Tue, Jun 20, 2017 at 02:24:51PM +0800, Han Lu wrote:
>But if I put 'i' command before 'd' command, shouldn't the input new lines
>be deleted ? Since new inputed lines contain the pattern 'd' command want.

There is a subtlely in the 'i' (insert) command:
The added content is not stored in the pattern space and is
not subject to later manipulations (such as pattern matching, 's///'
and 'd').

The GNU sed manual says:

   i = Immediately output the lines of text which follow this command.

Observe the following:

   $ seq 3 | sed -e 1iX -e 's/X/Y/'
   X
   1
   2
   3

And similarly with match+delete command:

   $ seq 3 | sed -e 1iX -e '/X/d'
   X
   1
   2
   3


Similar subtlety also applies to 'a' (append) and 'c' (change) commands.

The manual should probably be improved to explicitly mention
these points (added to my mental 'todo' list).


regards,
- assaf







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

Previous Next


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