How to remove the blank spaces and line breaks at the end