How to find a space in a text. using grep?

If you want to grep for just one space as you put in your question, you would use something like:

grep -e '^\s[^\s]' -e '[^\s]\s$' -e '[^\s]\s[^\s]' a.txt

or for POSIX variants:

grep -e '^ [^ ]' -e '[^ ] $' -e '[^ ] [^ ]' a.txt

or the less readable POSIX variant:

grep '\(^\|[^ ]\)\ \([^ ]\|$)' a.txt

Assuming you want to exclude lines that contain more than one adjacent space, this explicitly requires there be one space, not preceded by a space and not followed by a space.

Also, it's worth noting that not all versions of grep support '\s' regular expression controls.


I think I found it:

grep  "\+[[:space:]]\+" a.xml

Tags:

Grep