LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   highlighting text in the console (https://www.linuxquestions.org/questions/linux-newbie-8/highlighting-text-in-the-console-351381/)

tommmmmm 08-09-2005 12:18 AM

highlighting text in the console
 
I want to view the file, but i want to distinguish some lines of the file. I want to highlight them in some kind/ change their color. You know what i mean.

I did linuxgoogle searches, asked on jabber linux channel and did aprpopos highlight
but nothing found. I also searched this forumn.







ps: don't tell me that it's impossible, it's possible, i did such thing with turbo pascal under the linux console

heema 08-09-2005 03:53 AM

what editor have you tried ?

and whats the file type ?

because there are alot of editors that support syntax highlighting like vim , emacs , kwrite , gedit , .........

tommmmmm 08-09-2005 08:09 AM

no.................. not editors. ABSOLUTELY NOT.

i want to do smth like "cat file" but lies that match "grep expression" should be distinguished by another color.

So saying once more, i want to "cat file" the whoooooole file but i want to distinguish some lines, some particular lines (changing their colors) that match the grep expression.


that's all.

frankie_DJ 08-09-2005 06:09 PM

You can use some pager, like 'less' or 'more' or 'pg' to view the file. Once you open it (i.e. with 'less file_name'), search for pattern "schmoopsie" by typing
Code:

/schmoopsie
This will highlight 'schmoopsie' everywhere in the text. You can go from one highlight to another by pressing N key.

I am pretty sure this is what you remember doing.

tommmmmm 08-09-2005 11:56 PM

I already knew that trick. It enables me to do some basic regexp.
But what if i want to use awk or extended regexp? I also ment ( and wrote it above ) that i want to change the color of the lines.
I have already read tput and terminfo manuals and i can do any bolding/blinking and highlighting.

output of ls command is colorful. I would like to achieve similar effect.

andy753421 08-10-2005 01:44 AM

I cant figure out what you need, but check out this command, it may help

echo "\033[32m hi"

tommmmmm 08-10-2005 09:11 AM

this comand is a normal echo. It does not do ANYTHING.

i'll repeat you - I don't know what you mean.

frankie_DJ 08-10-2005 10:20 AM

You will have to do a better job explaining us what you need if you want us to help.

We have given you couple of solutions already and neither of them satisfies you. Andy was trying to show you that you can change color of things that you want printed on the screen by using nonprinting characther \033 as escape sequence. Do this

Code:

schmoopsie=`echo X|tr X '\033'`
you just stored your escape sequence into the variable schmoopsie. Now you can use it to change the color of text:

Code:

echo "$schmoopsie[1;33m whass up yo"
You can do other things to:

Code:

echo "$schmoopsie[5m$schmoopsie[1;33mLook at me I am blinking"
Now I guess you can figure out what to do with it. You might wanna alias grep or something to do stuff like that for ya. I can't really help you more cause I don't understand what you need.
Oh yeah, and a little more patience and occasional 'Thank you' wouldn't hurt either.

tommmmmm 08-10-2005 10:43 AM

you example works perfect ! Thanks very much

I don't know why simple echo <smth smth> didn't work, but your way of doing things works for me.

thank you.

http://www.tldp.org/LDP/abs/html/col....html#AEN15210

btw.
you could have posted it at the beginning... :tisk: :tisk:

frankie_DJ 08-10-2005 01:33 PM

No problem. I don't exactly understand why it doesn't work Andy's way either. Maybe someone else can elaborate on that.

andy753421 08-10-2005 02:30 PM

Hmm.. It seems to only work as an echo when useing a certain shell, Zsh (my default), tcsh, both seem to work, while sh, csh, and bash dont.


All times are GMT -5. The time now is 08:08 AM.