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
View this message in rfc822 format
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.
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.