NetBSD-Bugs archive

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

Re: bin/59803: sed(1) conditional branch command confuses subsequent line addressing



The following reply was made to PR bin/59803; it has been noted by GNATS.

From: Valery Ushakov <uwe%stderr.spb.ru@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc: 
Subject: Re: bin/59803: sed(1) conditional branch command confuses subsequent
 line addressing
Date: Sun, 30 Nov 2025 13:13:34 +0300

 On Sun, Nov 30, 2025 at 12:42:52 +0300, Valery Ushakov wrote:
 
 > A bit further down in the man page:
 > 
 >   A command line with two addresses selects an inclusive range.  This
 >   range starts with the first pattern space that matches the first
 >   address. [...]
 > 
 > The pattern space with the third line in it never matched the first
 > address of 3,$ range b/c "t" command caused that bit of the sed script
 > to be skipped over.  That seems like a pretty straightforward
 > procedural semantic.
 > 
 > The interpretation you seem to expect (declarative in spirit, not
 > procedural) makes address ranges (two addresses) behave radically
 > different from single address, if I understand correctly.  AFAICT you
 > expect all range toggles to always get checked regardless of the
 > program flow, but the action part to only get executed according to
 > the program flow.  Just thinking about that makes my head hurt :)
 
 Consider the "same" program in awk
 
   $ cat t.awk
   { print NR }
   /a/ { sub(/a/, "substitution succeeded"); print; next }
   (NR == 3), 0 { print }
 
   $ printf '%s\n' b a b b | gawk -f t.awk
   1
   2
   substitution succeeded
   3
   b
   4
   b
 
 
   $ printf '%s\n' b b a b b | gawk -f t.awk
   1
   2
   3
   substitution succeeded
   4
   5
 
 -uwe
 


Home | Main Index | Thread Index | Old Index