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

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

Re: Strange sed behavior


From: Stephane CHAZELAS
Subject: Re: Strange sed behavior
Date: Thu, 18 Oct 2007 18:00:26 GMT
User-agent: slrn/0.9.8.1pl1 (Debian)

2007-10-18, 14:47(+02), David Kastrup:
>
> Can anybody explain to me what is happening here?  I am a bit befuddled.
>
> $ { echo 1;echo 2;}|sed 'H;${x;P;D;}'
[...]

Your code is doing

$h = $p = ""

while ($p = readline()) {
START:
  $h = $h . "\n" . $p;      # H
  if (lastline) {
    ($h, $p) = ($p, $h);    # x
    print firstlineof($p);  # P
    removefirstlineof($p); if ($p != "") goto START; # D
  }
}

So, once you've reached the last line, you'll enter a loop where
the size of the pattern space will almost double in each pass.

Most seds have a limit on the size of the pattern and hold
space, GNU utilities generally don't have size limitations. So
it will end up using all the available memory on your system.

-- 
Stéphane




reply via email to

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