Q:

How to only print a line if a blank line follows

From some program, I get output of the form
aaaaa
bbbbb

ccccc
ddddd
eeeee
fffff

ggggg
hhhhh
iiiii

including the final blank line.
I want to get only the last lines of each block, i.e. every line followed by a blank line:
bbbbb
fffff
iiiii

I tried with sed and checked (as usual) the sed1liners, but could not come up with something useful.

A:

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

A:

with awk:
awk '
    /^[[:blank:]]*$/ {print prev} 
    {prev=$0}
    END {if (length(prev)) print prev}
'

