Login or Register to Ask a Question and Join Our Community

Using color escape codes in less

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Using color escape codes in less
# 1  
Old 09-18-2008
Error Using color escape codes in less

Hi all,
Not sure how "for dummies" this question is, but I'd better use understatement...

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

less 394
Copyright (C) 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.

Attached are my colorlogs.pl and colorlogs.conf files, to complement this post.

Thank you in advance.

Last edited by Source2Exe; 09-20-2008 at 11:13 AM.. Reason: Change icon
# 2  
Old 09-24-2008
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with awk color codes based on condition

HI i have two files say test and test1 Test.txt Code: Lun01 2TB 1.99TB 99.6% Lun02 2TB 1.99TB 99.5% Lun03 2TB 1.99TB 99.5% Lun04 2TB 1.55TB 89.6% Code: Test1.txt Lun01 2TB 1.99TB 89.5% Lun02 2TB 1.99TB 99.5% Lun03 2TB 1.99TB 99.5% Requirement is to compare... (6 Replies)
Discussion started by: venkitesh
6 Replies

2. UNIX for Dummies Questions & Answers

Display file with escaped color codes

Hi, I have a file containing color codes: Fri May 25 17:13:04 2012: Starting MTA: exim4^ Loading cpufreq kernel modules...^How can I display it colorized on a linux terminal? (4 Replies)
Discussion started by: ripat
4 Replies

3. Programming

Using ANSI color codes in gcc compiled program

I have put some yellow color codes and works well. I call the funstion using print_usage(stderr, 0); I would like to know if there is any way, to store the ansi color codes in variables and then call them inside fprintf. Or have a format followed by the strings I want to output. ... (5 Replies)
Discussion started by: kristinu
5 Replies

4. UNIX for Advanced & Expert Users

CUPS printing and control escape codes

I ported application from SysV to Linux and run into troubles with printing. Application uses lp and HP JetDirect-based printers, it inserts HP control codes in the file and uses plain lp -d dest doc-file command to print it. The Linux (Ubuntu 8) has CUPS system, which I am not familiar... (0 Replies)
Discussion started by: migurus
0 Replies

5. Shell Programming and Scripting

'watch' not interpreting escape codes in bash script

Hi there, I'm fairly new to bash scripting and already having some troubles. I'm making a script that can print some series of strings in colors based in the information of a file, for simplicity let's say it only does: #!/bin/bash printf "\eWhen you execute this in the command line it... (1 Reply)
Discussion started by: Arashi
1 Replies

6. UNIX for Dummies Questions & Answers

Regular expression on hex color codes

I want to have all hex color codes in a given stylesheet in uppercase, so #fff should be converted to #FFF for instance. Here is the regular expression I use to match and convert hex color codes to uppercase: sed -e 's/^#({3}$)|({6}$)/^#({3}$)|({6}$)/' main.css However, no conversion to uppercase... (6 Replies)
Discussion started by: figaro
6 Replies

7. Ubuntu

rdiff-backup using escape codes on vfat thumbdrive

I thought it may be nice to use rdiff-backup to backup my websites to a thumb drive. But all the capital letters are substituted with octal escape codes. How can I over come this? There are no issues backing up to another ext3 drive. The source drive is ext3 the thumb drive is vfat mounted... (0 Replies)
Discussion started by: mikemc
0 Replies

8. UNIX for Dummies Questions & Answers

escape codes

I did a search and found the link for escape codes,- but I am not sure how to modify this script to set the margins. I started with a script that was already written on my system to set a printer to print landscape. I need to send an report that is in an ascii file to multiple printers from my... (1 Reply)
Discussion started by: MizzGail
1 Replies
Login or Register to Ask a Question

Featured Tech Videos