squeeze space-only lines; remove trailing spaces
append newline to file (when missing)