This question already has an answer here:

Folks, I want to know if there exists a command that just highlight some portions of the input text, rather than filtering it like grep does.

To give an example, suppose the following input text:

foo bar
gaz das

grep "bar\|gaz" input would print the first two lines, highlighting bar and gaz, but would not display xar.

I'm aware that I could simply set a big constant to the -C argument, so it would "always" show the context, like: grep -C1000 "bar\|gaz" input, but I'm not sure if that is efficient, or if there is a better tool for that.

marked as duplicate by don_crissti, Community Jan 5 '16 at 14:02

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



  egrep --color 'pattern|$' file

or if you want using grep

  grep --color -E 'pattern|$' file

"pattern|$" will match lines that have the pattern you're searching for AND lines that have an end -- that is, all of them. Because the end of a line isn't actually any characters, the colorized portion of the output will just be your pattern

  • 1
    -E is not needed, you can grep --color 'pattern\|$' file – chaos Jan 5 '16 at 13:57

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