trim trailing whitespace and add newline at eof