Some of the solutions suggested above utilize GNU grep.
If you are a Mac user, you can easily install GNU version of the commands into your Mac. You can do this by installing the GNU Command Line Tools. The easiest way is to use Homebrew, then brew install coreutils.
The default commands will still be MacOS version (unless you intentionally set otherwise), but when you want to use GNU version, you could just add a g
before the command. For example, sort
vs gsort
, grep
vs ggrep
. You can also check manual of the command the same way, e.g. man gsort
. Trust me this will make your life easier as a Mac user.
Also, in recent years default MacOS Terminal shell is zsh.
If you desire you can switch it back to bash
.