Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Here is my sed command:

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

It prints:

GH

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
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.