How to identify and remove invisible whitespace characters on gedit

geditwhitespace

I want to remove unnecessary whitespace on my css file. I am using grep with the command as follows:

$ grep -rn "[[:space:]]$"

Surprisingly, it is returning a hit on every line in the file. I search for instances of \t\n, \r\n and \n but could not find anything. How do I go about identifying the invisible whitespace and remove it?

Best Answer

Don't be surprised that your regexps with a \n don't match: The \n is the line separator, it's not in the line. Every line in your file ends with \n-- by definition.* You'll never find a \n inside a line.

One possibility is that you're looking at a Windows file on Unix, and your mystery character is \r (NB not \r\n), which your grep is not recognizing as part of the EOL.

To find out what your lines actually look like, use od -c.

*Footnote for the nitpickers: Except possibly for the final line, and on very old Mac OS systems, etc., etc.

Related Question