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: Paolo Bonzini
Subject: Re: sed 4.2.1 bug
Date: Tue, 10 Jul 2012 12:41:08 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120605 Thunderbird/13.0

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]