Subject: bug#23832: sed combine d with q

From: Xen <[email-masked]>
Date: Thu, 23 Jun 2016 10:31:58 +0200 (CEST)

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.

Same effect.

Just different logic ;-).

I guess it is intentional. The d command is the only thing that can wipe a 
line, but it will stop command execution and "start a new cycle". The 
following will wipe everything, but it can't wipe that newline:

sed "/^\r$/{:again;N;s/.*\n.*//;t again}".

It's just funkily incredible :p.

Oh well. I had another few lifetimes to waste.... on something ;-).

Regards.