GNU bug report logs - #23832
sed combine d with q

Previous Next

Package: sed;

Reported by: Xen <xen <at> dds.nl>

Date: Thu, 23 Jun 2016 09:01: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 #11 received at 23832 <at> debbugs.gnu.org (full text, mbox):

From: Xen <xen <at> dds.nl>
To: Assaf Gordon <assafgordon <at> gmail.com>
Cc: 23832 <at> debbugs.gnu.org
Subject: Re: bug#23832: sed combine d with q
Date: Thu, 23 Jun 2016 16:51:10 +0200
Assaf Gordon schreef op 23-06-2016 16:17:

> This behavior is by design, and mandated by POSIX:
> "d - Delete the pattern space and start the next cycle."
> http://pubs.opengroup.org/onlinepubs/009604599/utilities/sed.html#tag_04_126_13_03

> The "Q" command (a GNU Sed extension) might be of help:

That is so wonderful. I had yet not been imaginative enough to try the 
uppercase version of that command. I was using an online tutorial that 
has been there for a long time, but that never mentioned any such thing. 
So thank you. Very much.


> The Q command quits without printing the pattern space.

So simple and so obvious :). (I mean the need for it, also). It appears 
I was not the only person to think of this ;-).

Always happy to know you are not perfectly insane, only readily so ;-) 
:p.

> To learn more about GNU sed extension command, see here:
>   https://www.gnu.org/software/sed/manual/sed.html#Extended-Commands

Thanks.

> Alternatively, If you can not use GNU extension, combining two 'sed'
> might be the simplest work-around:
> 
>   $ printf "a\nb\n\nc\nd\n" | sed '/^$/q' | sed '$d'
>   a
>   b

Yes, I had not considered (or fully realized) that $ matches the last 
line. I was trying to avoid having to use tail just for this single 
thing.

> As such I'm closing this bug, but discussion can continue by replying
> to this thread.

You're welcome, and thanks.

Regards,

Bart.




This bug report was last modified 8 years and 120 days ago.

Previous Next


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