Discussion:
Empty address before negation
gilles_arcas@hotmail.com [sed-users]
2014-09-25 21:42:01 UTC
Permalink
Hi.

I just discover that an empty address may be negated (GNU sed 4.2). For instance, "!p" is a valid syntax and acts as a nop. Formerly, an instruction should be described as [address][!][function] and not as [address[!]][function] as I thought until now.

I don't see any use for this except as a way to comment a valid instruction. Any idea?

Gilles Arcas


[Non-text portions of this message have been removed]
Davide Brini dave_br@gmx.com [sed-users]
2014-09-25 23:07:18 UTC
Permalink
Post by ***@hotmail.com [sed-users]
Hi.
I just discover that an empty address may be negated (GNU sed 4.2). For
instance, "!p" is a valid syntax and acts as a nop. Formerly, an
instruction should be described as [address][!][function] and not as
[address[!]][function] as I thought until now.
I don't see any use for this except as a way to comment a valid instruction. Any idea?
It is documented in the info page and works as expected. A null address
(that is, a command with no address) matches all the lines, so negating it
matches no lines, and the associated command is never executed.
Appending the `!' character to the end of an address specification
negates the sense of the match. That is, if the `!' character follows
an address range, then only lines which do _not_ match the address range
will be selected. This also works for singleton addresses, and,
perhaps perversely, for the null address.
--
D.
Daniel Goldman dgoldman@ehdp.com [sed-users]
2014-09-26 19:54:09 UTC
Permalink
I also don't see any practical use for !p, because it is equivalent to
omitting the command. However, if the address is a shell variable, and
the variable is not defined or blank, then the sed command would not
run, so that's a possible use. But seems unlikely this would be done in
practice, it seems confusing.


!p suggests one might say there is always an address. In other words,
maybe a "null" or "empty" address is still an address (matches all
lines). Is that right? The GNU sed manual says "If no addresses are
given", which suggests "null address" is not an address. But calling it
"null address" suggests it is an address. Made me think some.


Thanks,
Daniel
Post by Davide Brini ***@gmx.com [sed-users]
Post by ***@hotmail.com [sed-users]
Hi.
I just discover that an empty address may be negated (GNU sed 4.2). For
instance, "!p" is a valid syntax and acts as a nop. Formerly, an
instruction should be described as [address][!][function] and not as
[address[!]][function] as I thought until now.
I don't see any use for this except as a way to comment a valid instruction. Any idea?
It is documented in the info page and works as expected. A null address
(that is, a command with no address) matches all the lines, so negating it
matches no lines, and the associated command is never executed.
Appending the `!' character to the end of an address specification
negates the sense of the match. That is, if the `!' character follows
an address range, then only lines which do _not_ match the address range
will be selected. This also works for singleton addresses, and,
perhaps perversely, for the null address.
Loading...