5

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?

k0pernikus
  • 14,853
  • 21
  • 58
  • 79

1 Answers1

7

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.*|$'
Anthony Geoghegan
  • 12,605
  • 7
  • 59
  • 62