Changing font and color in log file of Script

Hi,

We have process log with user defined error messages and information echos. I wanted to highlight error messgaes in that log file while writing in it. Is there any option with either echo or any other command which enables making text bold or we can change the font of body text of echo.

Any help is appreciated.

Satish

there is escape sequence defined which can be used with echo

\033[0m Normal characters
\033[1m  Bold
\033[4m   underlined
\033[5m  Blinking
\033[7m  Reverse video

copy below lines into script and redirect output to file.

echo "\033[1m this a bold message\033[0m"
echo this is a normal message
echo "again normal"
echo "\033[1m again bold\033[0m"
echo "\033[7m reverse set ok\033[0m"

Hi Dhruva,

Thanks for the help. I tried these, it worked when I ran the commands on terminal.

But when I stored the echo in log file and vi log file, it shows something different.

e.g
$echo "\033[1m this a bold message\033[0m" > log
$ cat log
this a bold message
$ more log
this a bold message
$vi log
"log" 1 line, 29 characters
^[[1m this a bold message^[[0m
~
Similarly I downloaded the log file and opened in Microsoft word, it shows the result same as vi.

Do you know any commands or echo options which will store the character in file with special formatting which we specify with echo options.

Thanks,
Satish

yes we have tput command see man page for tput.I don't know how you will
see bold characters in vi.because vi is not designed to be like that.

You can rename the log file with .c extension and then whleprinting the error messages print them within " " or within /* */

[code]
echo "\"ERROR MESSG\"" > log.c
echo "/ANOTHER ERROR/" >> log.c

[code]

now when i do vi log.c you will see
[color=red]"ERROR MESSG"[color]
[color=blue]/ANOTHER ERROR/[color]

maybe this kinda result is not expected, but thats the best i could think of :stuck_out_tongue:

hope this helps :smiley: