---
tags: debug
---
# Using regular expression in grep on mac by installing GNU version
When following this [wonderful tutorial for grep on Youtube](https://www.youtube.com/watch?v=VGgTmxXp7xQ), 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
```UNIX
brew install grep --with-default-names
```
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
```UNIX
brew install grep
```
After installation, When we type
```UNIX
grep -V
```
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
```UNIX
grep -V
```
and you should see something like this

After successfully setting the grep to the GNU version, we can search for words using regular expression

## Reference
1. [Youtube tutorial](https://www.youtube.com/watch?v=VGgTmxXp7xQ)
2. [add PATH](https://apple.stackexchange.com/questions/193288/how-to-install-and-use-gnu-grep-in-macos)
3. [All of Programming Textbook](https://play.google.com/store/books/details?id=-zViCgAAQBAJ)