Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Using color escape codes in less Post 302237689 by Source2Exe on Thursday 18th of September 2008 07:23:52 AM
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
 

8 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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
XCOLORS(1)						      General Commands Manual							XCOLORS(1)

NAME
xcolors - display all X11 color names and colors SYNOPSIS
xcolors [ -start color ] [ -near color ] [ -distance howfar ] DESCRIPTION
xcolors reads the rgb.txt file that defines the color names the X server knows and displays the colors found. At the top of the window is a sample region containing text. By clicking on the color names, the color of the sample text can be changed. Mouse button 1 changes the foreground; button 2 changes the background. The text can also be edited. Typing ``q'' exits the program. OPTIONS
In addition the the usual X Toolkit options, xcolors understands these command line options: -start name specify a color name to start with; colors before this one in the rgb.txt file are skipped. This option is useful if there are more colors than will fit on your screen or in your colormap. -rgbfile filename specify an alternate color database file to read. -near nearcolor only show colors near this one in the RGB space. All colors within a sphere in the RGB-space centered on nearcolor are displayed. -distance howfar defines how close colors have to be to nearcolor to be displayed. This option sets the radius of the sphere used by the -near option. The scale is such that the RGB cube is 256 units on a side. The default is 64. ACTIONS
set-foreground([color]) Set the foreground color of the sample region. If no color is provided, the color is taken from the border color of the widget where the action occurred. set-background([color]) Same as set-foreground() but sets the background color. quit() Exit xcolors. RESOURCES
Xcolors has a few top-level application resources that allow customizations that are specific to xcolors. startColor (classStartColor) See the -start option. rgbFile (classRgbFile) See the -rgbfile option. nearColor (classNearColor) See the -near option. nearDistance (classNearDistance) See the -distance option. WIDGET HIERARCHY
Knowing the name and position in the hierarchy of each widget is useful when specifying resources for them. In the chart below, the class and name of each widget is given. Xcolors xcolors Paned panes AsciiText sample Viewport viewport Box colors Label colorname Label colorname . . . FILES
/etc/X11/rgb.txt X color names and values. BUGS
Assumes that all names for the same color are consecutive in the rgb.txt file. Because xcolors cannot read the server's color name database, the color names it uses may not match those in the server. This is most likely to happen if xcolors is run from a remote host. The program would be faster if it used gadgets instead of widgets for the color spots. AUTHOR
Stephen Gildea, MIT X Consortium X Version 11 3 October 1991 XCOLORS(1)
All times are GMT -4. The time now is 11:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy