Examples from: Linux Journal article
The first two examples work, but the third does not, as expected from the article. Can someone explain why? I have tried on both Ubuntu 22.04.1 and RHEL9, with the same result.
My screen:
[primus@rhel9 sandbox]$ cat filename.doc
The fast dog is fast.
The faster dogs are faster.
A sick dog should see a dogdoc.
This file is filename.doc.
[primus@rhel9 sandbox]$ grep "fast*" filename.doc
The fast dog is fast.
The faster dogs are faster.
[primus@rhel9 sandbox]$ grep "dogs*" filename.doc
The fast dog is fast.
The faster dogs are faster.
A sick dog should see a dogdoc.
[primus@rhel9 sandbox]$ grep "*.doc" filename.doc
[primus@rhel9 sandbox]$
[primus@rhel9 sandbox]$
But as extended regex, the third example works:
[primus@rhel9 sandbox]$
[primus@rhel9 sandbox]$ egrep "*.doc" filename.doc
A sick dog should see a dogdoc.
This file is filename.doc.
[primus@rhel9 sandbox]$ grep -E "*.doc" filename.doc
A sick dog should see a dogdoc.
This file is filename.doc.
[primus@rhel9 sandbox]$
grep "dogs*" filename.docreturned three lines? – jsotola Aug 23 '22 at 06:28dogs*matches ondogfollowed by 0 or moress.grep 'dogs*'is equivalent togrep dog. While*.docmatches on a literal*followed by any single character followed bydoc.grep -E '*.doc'would return an error as*doesn't follow anything. – Stéphane Chazelas Aug 23 '22 at 06:29*.docis not a valid extended regexp, butgrep -E '*.doc'is not required to return an error. Its behaviour is unspecified, and varies between implementations, some return an error, some (like GNU grep) treat it the same asgrep '.doc'– Stéphane Chazelas Aug 23 '22 at 06:57grep '*.doc'(without-E) is required by POSIX to match on a literal*followed by a single character followed by a.as in BRE*matches itself if it's at the beginning of the regexp or following\(. – Stéphane Chazelas Aug 23 '22 at 06:59