egrep search for whitespace
I see the same issue on SunOS 5.10. /usr/bin/egrep
does not support extended regular expressions.
Try using /usr/xpg4/bin/egrep
:
$ echo 'this line has whitespacethislinedoesnthave' | /usr/xpg4/bin/egrep '[[:space:]]'this line has whitespace
Another option might be to just use perl:
$ echo 'this line has whitespacethislinedoesnthave' | perl -ne 'chomp;print "$_\n" if /[[:space:]]/'this line has whitespace
If you're using 'degraded' versions of grep (I quote the term because most UNIX'es I work on still use the original REs, not those fancy ones with "\s
" or "[[:space:]]
" :-), you can just revert to the lowest form of RE.
For example, if :space:
is defined as spaces and tabs, just use:
egrep '[ ^I]' file
That ^I
is an actual tab character, not the two characters ^
and I
.
This is assuming :space:
is defined as tabs and spaces, otherwise adjust the choices within the []
characters.
The advantage of using degraded REs is that they should work on all platforms (at least for ASCII; Unicode or non-English languages may have different rules but I rarely find a need).