How to find trailing spaces with sed?
by lucmove from LinuxQuestions.org on (#5MM8T)
I have a file that I know has a trailing space in some lines.
I thought I could remove them with sed:
Code:$ sed 's/ $//' file.txt > newfile.txtIt doesn't work. The trailing spaces are still there.
Maybe there is something wrong with my code. I spot a line that contains a trailing space:
Quote:
Code:$ cat file.txt | sed '/ $/!d'That line is not present in the output. Never mind that line. Not one single line is in the output.
Well, maybe those are not trailing spaces after all. I know the file has been handled by someone who uses Windows. So maybe it is some other mysterious character?
So I manually edit the file and manually add trailing spaces, with my own Deluxe Linux-Compatible Space BarTM, to three random lines and save the file.
Code:$ cat file.txt | sed '/ $/!d'The output is still empty!
What am I doing wrong?
TIA
I thought I could remove them with sed:
Code:$ sed 's/ $//' file.txt > newfile.txtIt doesn't work. The trailing spaces are still there.
Maybe there is something wrong with my code. I spot a line that contains a trailing space:
Quote:
This line contains a trailing space. |
Well, maybe those are not trailing spaces after all. I know the file has been handled by someone who uses Windows. So maybe it is some other mysterious character?
So I manually edit the file and manually add trailing spaces, with my own Deluxe Linux-Compatible Space BarTM, to three random lines and save the file.
Code:$ cat file.txt | sed '/ $/!d'The output is still empty!
What am I doing wrong?
TIA