--- 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 ![](https://i.imgur.com/BtRo4Pn.png =400x) 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 ![](https://i.imgur.com/HjDoY3v.png =600x) Then we MUST reopen the terminal and check the version again ```UNIX grep -V ``` and you should see something like this ![](https://i.imgur.com/4hHWL2J.png =500x) After successfully setting the grep to the GNU version, we can search for words using regular expression ![](https://i.imgur.com/29XUaNC.png =500x) ## 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)