Append color in shell script for output

Hi Experts,

I want to get my shell script output in a color for a particular word. PFB my output.

TT.QM.JTV1S1    TLORSBT2.JMR701T1.C1 REPOS
TT.QM.JTV1R1    TLORSBF2.JMR701T1.C1  NORMAL

whenever REPOS word comes then entire line should come in red color. Can you please help me out on this.

awk '/REPOS/ {print "^[[31m" $0 "^[[0m"; next} {print}' your-input-file

"^[" is one non-printable character of Escape. You need to do 'Ctrl-V' follow by 'Esc' to input Escape.

Or:

awk '/REPOS/ {$0=sprintf("%c[41m%s%c[0m",27,$0,27)}1'  infile

it is not giving the expected output in script, but it is working in single line script and O.P is coming like below

^[[41mBT.QM.REPQ01D2 SIBEMBT2.REPQ01D2.C1 BT.CL.SIBEMBT2 70.75.112.113 51422 REPOS^[[0m
^[[41mBT.QM.REPQ02D2 SIBRMBT2.REPQ02D2.C1 BT.CL.SIBEMBT2 70.75.112.114 51422 REPOS^[[0m

---------- Post updated at 05:35 AM ---------- Previous update was at 05:01 AM ----------

and can you please explain what does below do?

("%c[41m%s%c[0m",27,$0,27)}1

27 is the ascii value of the ESC character

The awk program pre-pends <ESC>[41m (VT100 set red rackground)
and appends <ESC>[0m (VT100 reset to normal output).

You can try it out yourself on a xterm/vt* terminal with:

awk 'BEGIN { printf("%c[41m%s%c[0m\n", 27, "Testing", 27); }'

The above will print Testing with red background.