DeleteTrailingNewlines

Simple oneliner that deletes the trailing newlines of a file:

awk '!NF{b=b "\n";next} {printf "%s%s",b,$0;b="\n"}' file

Explanations:

The effect is that the newlines are only printed before non blank lines, the trailing newlines are stored in b, but never printed.

If you want to keep one trailing newline, add one ;):

awk '!NF{b=b "\n";next} {printf "%s%s",b,$0;b="\n"} END {print "\n"}' file