I am used to grep being able to color the filename, the line number, and the match itself. These three ought to be different colors. This works flawlessly on a Linux terminal and even MinGW on Windows, but on OS X even if I set GREP_COLOR I can only get color on the matched result.

Is the version of grep packaged with the OS too old?

10.7.3 on MBA 13" with Terminal.app.


As Ignacio already said, OS X grep is a bit outdated (it's version 2.5.1). You can install the latest GNU grep though.

As always, you can install most missing Linux tools on OS X through Homebrew, but its policy is not to offer duplicates for system tools. There's an alternative repository for these dupes, but you have to "tap" it first:

brew tap homebrew/dupes/

Then you can install the new grep (version 2.11 as of May 2012):

brew install homebrew/dupes/grep

Be aware that /usr/bin still comes first in your PATH, so you need /usr/local/bin/grep for the new version.

| improve this answer | |
  • What's a nice way to get grep to run from the new location? an alias? – Steven Lu May 2 '12 at 22:14
  • 2
    @StevenLu, you may want to put /usr/local/bin before /usr/bin. e.g., you can do this globally by editing /etc/paths, or have your shell startup script (e.g., ~/.bash_profile) edit PATH to change the order. – Chris Page May 3 '12 at 6:20
  • 2

Correct. Multiple colors were first supported in GNU grep 2.5.3.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.