I know how to grep 2 keywords using 1 command, but I can only manage to color one of them in output . Here is my command:
grep 'keyword1' file.log | grep 'keyword2'
Only keyword2
is highlighted. How can I make keyword1
highlighted at the same time ?
Best Answer
The
grep
command accepts a--color=always
option, so you can useAs gertvdijk points out, this command may be inefficient, but it will look for all lines that contain both keyword1 and keyword2. If you want to highlight them in different colors, you can use
which will highlight keyword2 in blue. The
mt
part means thatgrep
will highlight matching text using this CSI code, and01;34
means "bold blue foreground on normal background".