Is there a neat way to run a grep command ignoring the font color, but without losing the color.
For example, calling:
( echo 1 ABC ; echo 2 123 ; echo 3 A2C ; echo 4 ABCD ; echo 5 123D ; echo 6 A2CD ) |
egrep 'A.C|' |
grep -v BCD
I get the correct output.
1 ABC
2 123
3 A2C
5 123D
6 A2CD
With the 4th row filtered out, but I lose the highlight of the A.C expression (in lines 1, 3, and 6).
Trying to maintain highlight by adding --color=always:
( echo 1 ABC ; echo 2 123 ; echo 3 A2C ; echo 4 ABCD ; echo 5 123D ; echo 6 A2CD ) |
egrep --color=always 'A.C|' |
grep -v BCD
The 4th line is no longer filtered out:
1 ABC
2 123
3 A2C
4 ABCD
5 123D
6 A2CD
I encounter this issue in various scenarios, for instance, when running grep on the output of a grep run across multiple files.
In many cases, the second grep expression includes both the filename (before the : symbol, which is highlighted) and a substring of the content (after the :‘ symbol).
How can I do this all without losing the color formatting from the initial grep?