GNU bug report logs -
#23832
sed combine d with q
Previous Next
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 #14 received at submit <at> debbugs.gnu.org (full text, mbox):
On Thu, 23 Jun 2016 10:31:58 +0200 (CEST), Xen <xen <at> dds.nl> wrote:
> Hey, I am not sure if this is "by design" or not but....
>
> Suppose a text file with empty lines here and there. You want to print up
> to, but not including, the first newline.
>
> The first "^$", I mean.
>
> My idea was to use "/^$/{d;q}. I was under the assumption that both
> commands would get executed.
>
> However q is not executed.
>
> However when we reverse it, and use sed "/^$/{p;q}"; the effect is that
> the first matching newline (empty line) is printed twice, and then the
> program quits. So {p;q} works, but {d;q} doesn't.
>
> You are allowed to double the newline (empty line), but not remove it....
>
> Now when I use:
>
> sed -n "/^$/!p;/^$/q", as a way of not printing the first matching
> newline, and then quitting, which is basically the same as deleting it
> (this feels like if it is sunny weather; cry and moan, but you are not
> allowed to do so; instead, you must cry when it is not cloudy, and moan
> when it is sunny.
You can use
sed -n '/^$/q; p'
--
D.
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.