[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#23832: sed combine d with q
From: |
Xen |
Subject: |
bug#23832: sed combine d with q |
Date: |
Thu, 23 Jun 2016 16:51:10 +0200 |
User-agent: |
Roundcube Webmail/1.2.0 |
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.