Sed One Liners is great web page.
# delete BOTH leading and trailing whitespace from each line
sed 's/^[ \t]*//;s/[ \t]*$//'
# delete ALL blank lines from a file (same as "grep '.' ")
sed '/^$/d' # method 1
sed '/./!d' # method 2
http://sed.sourceforge.net/sed1line.txt
I would think that combination should work.