[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#23832: sed combine d with q

From: Davide Brini
Subject: bug#23832: sed combine d with q
Date: Thu, 23 Jun 2016 17:10:40 +0200

On Thu, 23 Jun 2016 10:31:58 +0200 (CEST), Xen <address@hidden> 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'


reply via email to

[Prev in Thread] Current Thread [Next in Thread]