I have coreutils but I am not sure if GNU grep is there.
I just want to use the flag -P
for Perl regex that is found in GNU grep, but not in BSD grep.
My PATH is /usr/local/opt/coreutils/libexec/gnubin:/usr/local/bin:/usr/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/git/bin:/usr/texbin:/Users/masi/.cabal/bin
so I have coreutils first in the PATH.
However, grep is BSD when I am using it: grep --version
gives grep (BSD grep) 2.5.1-FreeBSD
.
Command type -p grep
returns /usr/bin/grep
How can you install GNU Grep in macOS?
Best Answer
GNU grep is not part of coreutils. To install, run
As with coreutils, this doesn't automatically replace the existing grep
So after installing you can either use
ggrep
,gegrep
andgfgrep
; or extendPATH
as shown above to usegrep
etc. The second option may confuse some macOS specific scripts though in case the options differ.