2

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
xar

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.

Kira
  • 4,807

1 Answers1

5

USE:

  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

Ijaz Ahmad
  • 7,202