You might already know how to use the --color option to highlight matched portions with GNU grep. In this post, you'll see how to use ANSI escape sequences to format matched portions with GNU sed and GNU awk.
Consider this sample input file:$ cat fruits.txt banana mango cherry pineapple grape fig apple dragonfruit papaya watermelon cashew tomato orange almond lime grapefruit walnut
See this section from my ebook on GNU grep for more details about this option. ripgrep has a more featured support for color formatting, see this section for an example.
Your choice of formatting goes between \033[ and m. You can use 01 for bold, 03 for italics and 04 for underline. 31 is for the color red, 32 for green and 34 for blue. Multiple formats can be specified by separating the parameters with a semicolon. Using 0 turns off the format (otherwise, it will persist in the current terminal session until turned off).
If you find a file that has accidentally saved such escape sequences, you can use cat -v to identify them.$ echo 'one (two) three' | grep --color=always '(two)' | cat -v one ^[[01;31m^[[K(two)^[[m^[[K three