September 28, 2025

how to view a text file with multiple color highlights

Use the "rg -p" (like grep) command to search for the term and use the option `--color 'match:fg:COLOR` to specify the color. You can chain multiple rg commands. Then at the end use "less -R" to view the output. 

 

For example, the following command search within the bible, highlight the search term, but also highlights the book/verse of the line

 

rg -p $1 ~/Downloads/esv-bible-2001.txt \

| rg --colors 'match:fg:magenta' -p ':[0-9]*[A-Za-z]+ [0-9]+:[0-9]+' \

| less -R