Sponsored Content
Full Discussion: Complex coloring in script
Top Forums Shell Programming and Scripting Complex coloring in script Post 302383422 by rwuerth on Tuesday 29th of December 2009 04:44:43 PM
Old 12-29-2009
I don't know of a way to turn off specific colors.

But I've got this to work on my dtterm (hp-ux using posix shell)

Code:
 
RED="$(tput setaf 1)"
BLU="$(tput setaf 4)"
YEL="$(tput setaf 3)"
OFF="$(tput sgr0)"
 
# given the line "Patti is great" I want to set the whole line to $RED 
#because it has the pattern "Patti" in it, but I want the word "is" to be
#yellow".
 
#variable DEF is set on the fly to the full line color.
 
#$BLU output just to establish I'm setting DEF properly
echo "Patti is great" | (DEF=${BLU};sed -ne s/Patti.*/${DEF}\&${OFF}/p)
 
#RED output
echo "Patti is great" | (DEF=${RED};sed -ne s/Patti.*/${DEF}\&${OFF}/p)
 
#FINAL output - RED 'Patti' YEL 'is' RED 'great'
echo "Patti is great" | (DEF=${RED};sed -ne s/Patti.*/${DEF}\&${OFF}/p) | sed -ne s/is/${YEL}\&${DEF}/p

You need the parenthesis to group the assignment to DEF and the sed statement into the same STDIN.

Basically, by setting the variable DEF on the fly, you can create the default color for the whole line. Then instead of turning yellow "OFF" after the word 'is' you just turn red back on with DEF.

This works for me, hopefully I didn't put a typo in. ;-)

---------- Post updated at 05:44 PM ---------- Previous update was at 05:17 PM ----------

Actually, further testing proved it didn't work I had DEF set in my environment, and when I unset it, I got spurious results, however the followig did work:

Code:
echo "Patti is great" | (DEF=${RED}; sed -ne s/.*Patti.*/${DEF}\&${OFF}/ -e s/is/${YEL}\&${DEF}/p)

I put the assignment to DEF and all seds into the same process using multiple -e's to separate out the sed patterns, and printing only on the last pattern of the line.
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Coloring personal text in vim

Hi, I want to color some personal text, such as my own name in vim editor. Can anyone tell me how this is done. Thanks, Sathya (1 Reply)
Discussion started by: skkrish2
1 Replies

2. UNIX for Dummies Questions & Answers

Syntax coloring for .pc files in VIM editor

Hi, i am using VIM editor through Putty. By the option of Syntax on in .vimrc file i am able to see syntax colors in .c and .cpp files but not in the files with .pc extension. How can this be done? :confused: (2 Replies)
Discussion started by: RuchK
2 Replies

3. Shell Programming and Scripting

Need complex script, anyone up for a challenge?

Default shell is /usr/bin/zsh Script will be running #!/bin/bash Need to pull information from database while using other scripts already made (not by me). Ok, so i need a script pulling certain information about a customer's router interfaces. I am using a ROUTER-DNS-NAME as variable $1 I... (3 Replies)
Discussion started by: ///NNM
3 Replies

4. Shell Programming and Scripting

complex find in script

How to I put my find command string into a script. It is currently to long to be entered manually at command line. for FNAME in `find /unixsxxx/interface/x.x/xxxxxx -type f \( -name '*.KSH' -o -name '*.sh' -o -name '*.sql' -o -name '*.ksh' \) -exec grep -il xxx.xxx.xxx.xxx {} \;`; do C=`grep -c... (5 Replies)
Discussion started by: TimHortons
5 Replies

5. Shell Programming and Scripting

Complex Script

hey... i had a big problem with my professor i have 3 simple archives in.txt -> had all timestamps of users logon (100lines) ex. 111111 222222 333333 out.txt -> had all timestamps of users logof (100lines) ex. 111113 222225 333332 commands.txt... (9 Replies)
Discussion started by: beandj
9 Replies

6. Shell Programming and Scripting

awk script (complex)

picked this up from another thread. echo 1st_file.csv; nawk -F, 'NR==FNR{a++;next} a{b++} END{for(i in b){if(b-1&&a!=b){print i";\t\t"b}else{print "NEW:"i";\t\t"b} } }' OFS=, 1st_file.csv *.csv | sort -r i need to use the above but with a slight modification.. 1.compare against 3 month... (25 Replies)
Discussion started by: slashbash
25 Replies

7. Shell Programming and Scripting

Bash script - coloring reg. expressions in text

Hi all, is there anyone good at bash who will help me? I need to use syntax ${string/pattern/replacement} The problematic part where I am stuck is: #!bin/bash text="A cat is on a mat." exp="cat" newexp="SOMECODEcatSOMECODE" newtext=${${text}/${exp}/${newexp}} == > ERROR "wrong... (4 Replies)
Discussion started by: JohnnyM77
4 Replies

8. UNIX for Dummies Questions & Answers

Coloring the pattern match

Hi All, Can we have colour the matched pattern with any color using unix command? For example I have a very length line a file and I'm applying grep on that file. grep "matched pattern" filename.txt My output is like below, ...........matched... (2 Replies)
Discussion started by: poova
2 Replies

9. Shell Programming and Scripting

Coloring cli output, screws up 'alignment'

Heyas I'm trying to add color 'support' to my TUI. It works, but behaves weird. Code in question: (status.conf) R="\033" ; TUI_WORK="" TUI_DONE="" ; TUI_FAIL="" TUI_SKIP="" ; TUI_NEXT="" TUI_BACK="" ; TUI_CANC="" TUI_ON="" ; TUI_OFF="" TUI_INFO="" ; TUI_HELP="" The... (4 Replies)
Discussion started by: sea
4 Replies
HOBBITGRAPH.CFG(5)						File Formats Manual						HOBBITGRAPH.CFG(5)

NAME
hobbitgraph.cfg - Configuration of the hobbitgraph CGI SYNOPSIS
$BBHOME/etc/hobbitgraph.cfg DESCRIPTION
hobbitgraph.cgi(1) uses the configuration file $BBHOME/etc/hobbitgraph.cfg to build graphs from the RRD files collected by Xymon. FILE FORMAT
Each definition of a graph type begins with a "[SERVICE]" indicator, this is the name passed as the "service" parameter to hobbit- graph.cgi(1). If the service name passed to hobbitgraph.cgi is not found, it will attempt to match the service name to a graph via the TEST2RRD environment variable. So calling hobbitgraph.cgi with "service=cpu" or "service=la" will end up producing the same graph. A graph definition needs to have a TITLE and a YAXIS setting. These are texts shown as the title of the graph, and the YAXIS heading respectively. (The X-axis is always time-based). If a fixed set of RRD files are used for the graph, you just write those in the RRDtool definitions. Note that Xymon keeps all RRD files for a host in a separate directory per host, so you need not worry about the hostname being part of the RRD filename. For graphs that use multiple RRD files as input, you specify a filename pattern in the FNPATTERN statement, and optionally a pattern of files to exclude from the graph with EXFNPATTERN (see "[tcp]" for an example). When FNPATTERN is used, you can use "@RRDFN@" in the RRD- tool definitions to pick up each filename. "@RRDIDX@" is an index (starting at 0) for each file in the set. "@RRDPARAM@" contains the first word extracted from the pattern of files (see e.g. "[memory]" how this is used). "@COLOR@" picks a new color for each graph automatically. The remainder of the lines in each definition are passed directly to the RRDtool rrd_graph() routine. The following is an example of how the "la" (cpu) graph is defined. This is a simple definition that uses a single RRD-file, la.rrd: [la] TITLE CPU Load YAXIS Load DEF:avg=la.rrd:la:AVERAGE CDEF:la=avg,100,/ AREA:la#00CC00:CPU Load Average GPRINT:la:LAST: %5.1lf (cur) GPRINT:la:MAX: %5.1lf (max) GPRINT:la:MIN: %5.1lf (min) GPRINT:la:AVERAGE: %5.1lf (avg) Here is an example of a graph that uses multiple RRD-files, determined automatically at run-time via the FNPATTERN setting. Note how it uses the @RRDIDX@ to define a unique RRD parameter per input-file, and the @COLOR@ and @RRDPARAM@ items to pick unique colors and a match- ing text for the graph legend: [disk] FNPATTERN disk(.*).rrd TITLE Disk Utilization YAXIS % Full DEF:p@RRDIDX@=@RRDFN@:pct:AVERAGE LINE2:p@RRDIDX@#@COLOR@:@RRDPARAM@ -u 100 -l 0 GPRINT:p@RRDIDX@:LAST: %5.1lf (cur) GPRINT:p@RRDIDX@:MAX: %5.1lf (max) GPRINT:p@RRDIDX@:MIN: %5.1lf (min) GPRINT:p@RRDIDX@:AVERAGE: %5.1lf (avg) ADVANCED GRAPH TITLES
Normally the title of a graph is a static text defined in the hobbitgraph.cfg file. However, there may be situations where you want to use different titles for the same type of graph, e.g. if you are incorporating RRD files from MRTG into Xymon. In that case you can setup the TITLE definition so that it runs a custom script to determine the graph title. Like this: TITLE exec:/usr/local/bin/graphitle The /usr/local/bin/graphtitle command is then called with the hostname, the graphtype, the period string, and all of the RRD files used as parameters. The script must generate one line of output, which is then used as the title of the graph. ENVIRONMENT
TEST2RRD Maps service names to graph definitions. NOTES
Most of the RRD graph definitions shipped with Xymon have been ported from the definitions in the larrd-grapher.cgi CGI from LARRD 0.43c. SEE ALSO
hobbitserver.cfg(5), rrdtool(1), rrdgraph(1) Xymon Version 4.2.3: 4 Feb 2009 HOBBITGRAPH.CFG(5)
All times are GMT -4. The time now is 07:59 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy