How to remove excess whitespace from a document?
I want to remove excess whitespace from the ends of lines in a document, but this code doesn't work:
Code:
$ cat input.txt | sed 's/[ \t]*$//' > output.txt Code:
cat input.txt | sed 's/^[ \t]*//;s/[ \t]*$//' > output.txt |
Hi,
I ran your command and it worked fine. Not sure where the problem is. Are you, by any chance, trying to edit windows files? If so then try the following: Code:
sed 's/[ \t]*\r$//' Code:
dos2unix file |
Quote:
Code:
$ sed 's/[ \t]*$//' input.txt > output.txt What crts means by 'windows files' is plain text files that were created in a Windows application and hence have Windows style line endings (CR followed by LF) rather than Unix style (LF only). If you don't want to alter input.txt you can pipe it to dos2unix and pipe the output from dos2unix to sed. Code:
$ cat input.txt | dos2unix | sed 's/[ \t]*$//' > output.txt If you're still having trouble you could post input.txt as an attachment for people to experiment with. |
Quote:
Code:
$ dos2unix < input.txt | sed 's/[ \t]*$//' > output.txt |
Quote:
Code:
sed 's/[ \t]*\r$//' input > output |
All times are GMT -5. The time now is 04:46 PM. |