Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Here is my sed command:

echo -e "AB\nCD\nEF\nGH" | sed 'N; D;'

It prints:


while sed processing input line by line, what happens with the last line? (When after that sed saw End-Of-File)? I mean the pattern buffer only contains 1 line.

share|improve this question
up vote 2 down vote accepted

It halts processing. From the sed manual:

  • N : Add a newline to the pattern space, then append the next line of input to the pattern space. If there is no more input then sed exits without processing any more commands.

So it never gets to the D;, and you're left with just the last GH.

share|improve this answer
But N does not effect stdout. we saw GH because we have not set -n option? – Majid Azimi Apr 22 '12 at 3:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.