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.

0

1 Answer 1

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

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.