Re: Empty address before negation

"Daniel Goldman [email protected] [sed-users]" <[email protected]>
Newsgroups gmane.editors.sed.user
Message-ID <[email protected]>
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


On 9/25/2014 4:07 PM, Davide Brini [email protected] [sed-users] wrote:
> On 25 Sep 2014 14:42:01 -0700, "[email protected] [sed-users]"
> <[email protected]> wrote:
>
>> 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.
>
>>From the info page:
>
>     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.
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.