strip whitespaces at line end, add new line to the end if not.