When using grep --color=always
I can get pretty color highlighting for regex matches.
However, grep
only returns lines with at least one match. Instead, I am looking for a way to simply highlight regex matches, while leaving all other input alone, without dropping lines without any matches.
I have tried to get color working with sed
, and read the grep
documentation, but I can't seem to get what I want.
In case my description isnt obvious, I want:
INPUT:
- fred
- ted
- red
- lead
Regex:
- ".*red"
OUTPUT:
- fred ( in red )
- ted
- red ( in red )
- lead
So that I could do:
list_stuff | color_grep "make_this_stand_out_but_dont_hide_the_rest"
EDIT:
I have found a solution, which isn't pretty, but it works:
Thanks to: http://www.pixelbeat.org/docs/terminal_colours/
Particularly the script (which I modified/simplified): http://www.pixelbeat.org/talks/iitui/sedgrep
function sedgrep ()
{
C_PATT=`echo -e '\033[33;01m'`
C_NORM=`echo -e '\033[m'`
sed -s "s/$1/${C_PATT}&${C_NORM}/gi"
}
Still looking for an easier way to do this!