Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
    
This still work? --> superuser.com/questions/416835/… –  emgee May 2 '12 at 4:42
    
I just came from there. I did exactly what was described. Just one color got set. –  Steven Lu May 2 '12 at 4:45
add comment

2 Answers

up vote 3 down vote accepted

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.

share|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
1  
@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
1  
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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