GNU grep 2.5.4 on bash 4.1.5(1) on Ubuntu 10.04
This matches
$ echo "this is a line" | grep 'a[[:space:]]\+line'
this is a line
But this doesn’t
$ echo "this is a line" | grep 'a\s\+line'
But this matches too
$ echo "this is a line" | grep 'a\s\+\bline'
this is a line
I don’t understand why #2 does not match (whereas # 1 does) and #3 also shows a match. Whats the difference here?
Take a look at your
grepmanpage. Perl added a lot of regular expression extensions that weren’t in the original specification. However, because they proved so useful, many programs adopted them.Unfortunately,
grepis sometimes stuck in the past because you want to make sure yourgrepcommand remains compatible with older versions ofgrep.Some systems have
egrepwith some extensions. Others allow you to usegrep -Eto get them. Still others have agrep -Pthat allows you to use Perl extensions. I believe Linux systems’ grep command can use the-Pextension which is not available in most Unix systems unless someone has replaced the grep with the GNU version. Newer versions of Mac OS X also support the-Pswitch, but not older versions.