Re: sed N command with relative addressing

Paolo Bonzini <[email protected]>
Newsgroups gmane.comp.gnu.utils.bugs
Message-ID <[email protected]>
Il 16/05/2014 07:03, Hiroto Kagotani ha scritto:
> $ seq 1 10 | gsed '3,+3N; s/\n/-/'
> 1
> 2
> 3-4
> 5-6
> 7-8
> 9
> 10
> $ seq 1 10 | gsed '3,6N; s/\n/-/'
> 1
> 2
> 3-4
> 5-6
> 7
> 8
> 9
> 10
>
> `3,+3N' seems to be treated as `3,7N'.
> Is there any reason for the 2nd relative address to be relative to the
> next line of the 1st address only for N command?

Interesting.  This is because "+3" is treated as "3 evaluations of the 
address", for example:

$ seq 1 10 | sed -n '/[24680]/ {; 1,+3 p; }'
2
4
6

$ seq 1 10 | sed -n '/[24680]/ {; 5,+3 p; }'
6
8
10

$ seq 3 10 | sed -n '/[24680]/ {; /4/,+3 p; }'
4
6
8

I suspect this bug has been there forever, though I wouldn't be opposed 
to fixing it.

Paolo
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.