This question already has an answer here:
When using grep, it will highlight any text in a line with a match to your regular expression.
What if I want this behaviour, but have grep print out all lines as well? I came up empty after a quick look through the grep man page.
If you are looking for a pattern in a directory recursively, you can either first save it to file.
And then grep that, or pipe it to the grep search
This will look of listing all files, but colour the ones with uppercase letters. If you remove the last | you will only see the matches.
I use this to find images named badly with upper case for example, but normal grep does not show the path for each file just once per directory so this way I can see context.
You can make sure that all lines match but there is nothing to highlight on irrelevant matches
Notes:
egrep
may be spelled alsogrep -E
--color
is usually default in most distributionsIf you are doing this because you want more context in your search, you can do this:
Doing a search in
less
should highlight your search terms.Or pipe the output to your favorite editor. One example:
Then search/highlight/replace.
Maybe this is an XY problem, and what you are really trying to do is to highlight occurrences of words as they appear in your shell. If so, you may be able to use your terminal emulator for this. For instance, in Konsole, start Find (ctrl+shift+F) and type your word. The word will then be highlighted whenever it occurs in new or existing output until you cancel the function.