Branch on sed

View: New views
2 Messages — Rating Filter:   Alert me  

Branch on sed

by Norihiro Tanaka-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

Which is correct result for the following commands, in which branch
command is included, in POSIX ?

seq 1 10 | sed -ne '1,/4$/{p;b
} 1,/[36]$/p;'

- sed 4.1.0 or later

1
2
3
4
5
6

- sed 4.0.9 or former
  ( and Solaris 10 native, HP-UX 11i native, AIX 5.3 native)

1
2
3
4

Regards,
Norihiro




Re: Branch on sed

by Paolo Bonzini-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 10/03/2009 04:22 PM, Norihiro Tanaka wrote:
> Hi,
>
> Which is correct result for the following commands, in which branch
> command is included, in POSIX ?

Indeed GNU sed 4.1.0 made line number addresses are "absolute": you do
not need to match the address on the exact line corresponding to the
first address in order to activate it.

I don't remember exactly but POSIX either does not specify it or
specifies it like GNU sed 4.1.0 and newer do.  I also think that BSD sed
implements it too (because I learnt about this behavior when I
incorporated the BSD sed testsuite into GNU sed).

Here is another example that shows why GNU sed's behavior is preferrable:

seq 1 10 | sed -e '1,4d;3,6d'

Paolo