Working with some input/commands which dealt with multiline pattern
spaces, noticed a behaviour I was not expecting. Reducing the test to a
simple case:

  $ echo "foo\nbar\nbaz" | sed "1d; N"
  bar
  baz
  $

This is for 3 lines of input. However, same command but for 4 lines of
input:

  $ echo "foo\nbar\nbaz\nqux" | sed "1d; N"
  bar
  baz   <--- qux not here
  $

For 6 lines of input:

  $ echo "foo\nbar\nbaz\nqux\nquux\nquuz" | sed "1d; N"
  bar
  baz
  qux
  quux  <--- quuz not here
  $

(use echo -e if on bash)

When the input has an even number of lines, the last line disappears. My
understanding is this isn't supposed to happen, but I'm unsure if it has
something to do with POSIX gray areas of undefined behaviours. For
instance, GNU sed from ports presents a different behaviour (second test
case but with gsed):

  $ echo "foo\nbar\nbaz\nqux" | gsed "1d; N"
  bar
  baz
  qux   <--- qux here
  $

Before suggesting anything, anyone with a stronger experience on sed
historical behaviours can shed some light on if this is acceptable?

Thank you.

-- 
db

Reply via email to