When following this wonderful tutorial for grep on Youtube, we see that the BSD version of grep on mac does not support regular expression. The installation for the GNU version of grep in the tutorial is
However, we get an error message:
Error: invalid option: โwith-default-names
because the "โwith-default-names" has removed from homebrew. So, instead, we should use
After installation, When we type
in command line, the version might still not be GNU, but looks something like
We need to paste the line
PATH="/usr/local/opt/grep/libexec/gnubin:$PATH"
into the
usr/.bash_profile file
so that the computer sets the GNU version as default.
Some part of the usr/.bash_profile should look like
Then we MUST reopen the terminal and check the version again
and you should see something like this
After successfully setting the grep to the GNU version, we can search for words using regular expression