Currently, I use

egrep --color 'error|$'

to highlight every word in a line containing the word error:

enter image description here

I would like to highlight the entire line though so that the entire string appears in red.

How can I achieve that?

marked as duplicate by don_crissti, Costas, GAD3R, Bananguin, countermode Dec 15 '16 at 14:17

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.

  • @don_crissti I also want to see the lines not matching the pattern. – k0pernikus Dec 15 '16 at 11:59
  • yeah, I got it... see the suggested duplicate and also How to have tail -f show colored output – don_crissti Dec 15 '16 at 12:00
  • 1
    grep -E --color '.*error.*|^' – Costas Dec 15 '16 at 12:30
  • @Costas Exaclty what I was looking for. Please provide as answer, bonus point for explaining why it does what it does :) – k0pernikus Dec 15 '16 at 13:28

To highlight the complete line, you should expand the regex so that it includes all (if any) characters before and after the desired term. Do this by prepending and appending .* to the term being searched for:

echo "foo bar error baz" | egrep --color '.*error.*|$'
  • This will hide the other content not matching the pattern. I want to keep it. – k0pernikus Dec 15 '16 at 13:28
  • @k0pernikus Sorry, I omitted the |$ in the regex while testing. I've fixed that now. – Anthony Geoghegan Dec 15 '16 at 15:33

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