bug-gnu-utils
[Top][All Lists]
Advanced

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

Re: sed 4.2.1 bug


From: Sophia Jacob
Subject: Re: sed 4.2.1 bug
Date: Tue, 10 Jul 2012 22:31:32 +0530

Thank you very much Paolo!

Still it looks like 'D' is not working at all in this case. I ran this:
$ sed -n '=;i\
----
;p;H;4,${g;i\
+++
;=;D;h}' c    # c is the same file that contains 5 lines 1\n2\n3\n4\n5

(Print the pattern space at the beginning of the command. So, if 'D'
deletes the first segment of the pattern space (which will contain
"1\n2\n3\n4\n", in the next itteration, 'p' should be printing
"2\n3\n\4". But it keeps printing "1\n2\n3\n4"!

1
----
1
2
----
2
3
----
3
4
----
4
+++
4
4
----
1
2
3
4
+++
4
4
----
1
2
3
4
1
2
3
4
+++
4


On 7/10/12, Paolo Bonzini <address@hidden> wrote:
> Il 10/07/2012 12:26, Sophia Jacob ha scritto:
>> Hi,
>> I stumbled upon a possible bug in sed:
>>
>> $ cat c
>> 1
>> 2
>> 3
>> 4
>> 5
>>
>> $ sed -n 'H;4,${g;D;h}' c   # print the last 3 lines of a file
>> sed: couldn't re-allocate memory
>>
>> Basically, if 'D' is used after 'g' or 'G' or 'x' (after copying from
>> the hold space), this realloc error is thrown. I think this is a bug.
>> Please let me know if this is a usage error on my part.
>
> the D command automatically restarts the script (i.e. it is followed by
> an implicit b<first-command-in-the-script>.
>
> The effect you want can be obtained with the following command:
>
>    sed '1{;$!N;$!N;};$!N;$!D'
>
> where the number of printed lines is equal to the total number of N
> commands.  You can also avoid repeated $!N commands with a loop, like this:
>
>   :x
>   $q
>   $!N
>   4,$D
>   bx
>
> which will print the last 3 lines too.
>
> Paolo
>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]