SED delete only first line command - Help need

Can any one help me how the sed delete only first line command (D) works.

sed -f sedcmds File.txt

In this how the sed delete only first line command (D) works to delete the blank lines appearing more than ones leaving only one blank and deleting others blanks.
While doing step by step when two blank line appended in the pattern space, according to D command one blank is deleted in the pattern space leaving second one alone.
My question is what will happen to the remaining blank space, whether it will send as output immediately by clearing pattern space or append next pattern to that blank space???. After this how the next loop will start?
Can u explain this detailly... coz I couldn't able to find the detailed explanation for sed's D delete command in net.

sedcmds

/^$/{
       N
       /^\n$/D
       }

File.txt

This is line1

This is line2


this is line3




This is line4.

The sed man page is pretty clear about the function of the D command which says that the D command will cause the next cycle to start, but will prevent the reading of the next input line if the pattern space is not empty.

Thus, the way your programme works can be explained with a bit of pseudo code:

while not at end of file 
do
   if pattern space is an empty line  (/^$/)
   then
       read next line and append to pattern space (N)
       if pattern space is two empty lines   (/^\n$)
       then
           delete to the first newline  (D)
           goto loop (leaves a single empty line in the pattern space)
       end
   end

   print pattern space
   read next line

:loop
done

So, as sed encounters blank lines, it 'buffers' one of them in the pattern space until the pattern space contains a blank line followed by a line that is more than just a newline.

Hope this makes sense.

Try:

sed ':a;N;s/\n$//;ta' infile

or

sed -e :a -e 'N;s/\n$//;ta' infile