You have to play with the hold space
.
sed -ne '/^$/ { g; p; b }; h; $ { g; p }' infile
How does it work?
For each normal line, copy it to hold space
(h
) overwritting previous content. And for special cases (empty lines and last line of file), take the content of hold space and print it.
It yields:
bbbbb
fffff
iiiii