0

Hi I have a log file that has a lot of information and it is pretty difficult to spot what I am looking for, so I came to this command that show me only what I want to see in the log, it will act as a listener when the pattern is match only show me the search results

tail -f file.log | GREP_COLOR='01;36' egrep --color=always "\"stringOneExample\""

And works ok,the problem is if I pipe another grep

tail -f file.log | GREP_COLOR='01;36' egrep --color=always "\"jsonKeyOne\"" | GREP_COLOR='01;31' egrep --color=always "\"jsonKeyTwo\""

I think does not work because when I pipe one into the other as the result of the first does not contains the condition of the second, nothing is shown, so I want to both(or more) grep operate on the all file and just give each string a different color in order to spot the difference more easily

NOTE if I add :|$ to the end, it will act as a regular tail and show me a lot of extra info that is not what I want

 tail -f file.log | GREP_COLOR='01;36' egrep --color=always "\"stringOneExample\":|$"

1 Answer 1

0

Preferrably use:

grep -e 'jsonKeyOne' -e 'jsonKeyTwo'

…to OR your terms. Depending on your flavor of grep also -E 'jsonKeyOne|jsonKeyTwo' is possible, too. This is the fastest option with only the terms.

Different colors work like this: first term only colored and all other lines uncolored, next term with different color and all other lines, too …until last term with its color and also all other lines.

Either grep or syntax highlight, better not both.

2
  • Hi, this works! now it show me the result of both criteria, but still the colors are not present, it just mark as red all the matches, I am not sure if I miss something, can you help me?
    – jam
    Commented Mar 12, 2020 at 21:28
  • See the other answer above but mind what I wrote about the consequences: your expression will get more complex, since all other colors and greps must pass through all previous matches.
    – motzmann
    Commented Apr 16, 2020 at 17:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .