Computing.Net > Forums > Linux > Using color escape codes in less,

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Using color escape codes in less,

Reply to Message Icon

Name: source2exe
Date: September 21, 2008 at 05:42:12 Pacific
OS: Linux RedHat
CPU/Ram: #1 SMP Wed Oct 10 16:34:1
Product: 2.6.18-53.el5.
Comment:

Hi all,
Please forgive me if you saw this post in other forums as well. I just do not seem to get any answer....

A. My Environment
==============
I am using RedHat Linux, version 2.6.18-53.el5.
When I type less --version I get:

less 394
Copyright © 1984-2005 Mark Nudelman
...

My terminal is configured as Xterm, using ANSI colors and indeed, typing
ls --color=yes produces a colored list.

B. Background
===========
I am using a small pearl script that colors lines of text according to predefined key words.
This is a very nice utility. When I redirect tail -f output to it, it produces nice color logs of my server, with words such as "Exception" or "Error" conveniently colored.

Recently I wanted to try a more ambitious use of this script: To use it together with less command.

Anyone can understand, that less +F is better than tail -f, as one can press CTRL+C at any given time when viewing a file online, and scroll or search within it effortlessly, without ever returning to the shell prompt.

Which leads me to:

C. The Problem
===========
1. I can not get less to show color.
Even typing "ls --color=yes > test.txt"
and then less -r text.txt or less -R text.txt NEVER displays the content in color. The output is actually the same as doing a "ls --color=no"

2. I read a bit about less input preprocessor the related Environment Variables in UNIX man pages : less ().

3.But, I can not figure out how I can turn less to use colors on a regular basis, How I can make less to "relay" all its output through my color pearl script, and mostly - Is it possible at all?

Any help would be highly appreciated.

Thank you in advance.



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: September 22, 2008 at 13:26:54 Pacific
Reply:

This is out of my area, but I did see this link about setting up less with git:

http://rha7dotcom.blogspot.com/2008...

Maybe it'll give you some ideas.


0

Response Number 2
Name: source2exe
Date: September 24, 2008 at 06:00:05 Pacific
Reply:

OK. At last, success.
This is the only thing that is working, 100% to my satisfaction.

nohup less +F /var/log/Server.log | /usr/local/src/Colorlogs/colorlogs.pl > takethis.log &

less +F -f -R takethis.log

This works wonderfully.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Linux Forum Home


Sponsored links

Ads by Google


Results for: Using color escape codes in less,

In Squid ALLOW/DENY rules www.computing.net/answers/linux/in-squid-allowdeny-rules/26810.html

simple problemo.. www.computing.net/answers/linux/simple-problemo/28625.html

how to use 'cd' command in shell sc www.computing.net/answers/linux/how-to-use-cd-command-in-shell-sc/19123.html