Well this might seem blindingly obvious to some, but I was stumped for half an hour this morning trying to figure out why ‘grep he+’ wasn’t finding the word ‘hello’ in a test file when it was obviously there. The answer was that I should have read the manpage very carefully. The all-important paragraph reads as follows:
grep understands three different versions of regular expression syntax: “basic,” “extended,” and “perl.” In GNU grep, there is no difference in available functionality using either of the first two syntaxes. In other implementations, basic regular expressions are less powerful. The following description applies to extended regular expressions; differences for basic regular expressions are summarized afterwards.
Confused? So was I until I read the Wikipedia article on regex, which states that:
The basic Unix regular expression syntax is now defined as obsolete by POSIX, but is still widely used for backwards compatibility. Many regular-expression-aware Unix utilities including grep and sed use it by default while providing support for extended regular expressions with command line arguments.
So, the moral of the story is: if you want to use the regular expression syntax you found on that cheat sheet you downloaded, use ‘grep -E’!