Use awk to print syslog output to terminal with colors 
Author Message
 Use awk to print syslog output to terminal with colors

Running Redhat Linux
gawk-3.0.4-2

[Not directly awk related]

I've been experimenting with using awk to filter syslog output and
have written several filters that display what I want to see.  No
problems with that.

Now I want to use awk to insert whatever sequences are necessary to
display various parts in color on an xterm.  I have only a very vague
understanding of how colored output is generated but seems it would be
possible to use awk to add what ever is needed to get the proper display.

I am hoping someone here can steer me towared documentation that
covers this subject.



Fri, 16 May 2003 03:00:00 GMT  
 Use awk to print syslog output to terminal with colors

Quote:

> Running Redhat Linux
> gawk-3.0.4-2

> [Not directly awk related]

> I've been experimenting with using awk to filter syslog output and
> have written several filters that display what I want to see.  No
> problems with that.

> Now I want to use awk to insert whatever sequences are necessary to
> display various parts in color on an xterm.  I have only a very vague
> understanding of how colored output is generated but seems it would be
> possible to use awk to add what ever is needed to get the proper display.

> I am hoping someone here can steer me towared documentation that
> covers this subject.

On my system there's a manual page for "console_codes"
which details most options for colours.

The following awk might help too:

BEGIN{
  for(i=0;i<=9;++i)
    for(j=1;j<=2;++j)
      print "\033\["j";3"i"mhello \033\[0;37m"

Quote:
}

Have fun,

Tristan.



Fri, 16 May 2003 03:00:00 GMT  
 Use awk to print syslog output to terminal with colors


% Now I want to use awk to insert whatever sequences are necessary to
% display various parts in color on an xterm.  I have only a very vague

There's probably a way to get the tput command to emit the correct
sequences, and that's probably the best thing to use, but the simplest
is to just use ansi control sequnces. There's probably a web page out
there somewhere that says what the ansi control sequences are. In general,
they start with escape (\033), left bracket ([), then a list of numbers
separated by semi-colons (;), and finishing with a letter. For screen
colours, the letter is m. The numbers can be
 0 - normal intensity
 1 - high intensity
 4 - underline
 7 - reverse video
 8 - invisible
 3n - set foreground colour to n
 4n - set background colour to n

n can be from 0 to 7 (try them out to find out which colour is which).

So, to get high-intensity red on blue:

 print "\033[31;44;1mFabulous\033[31;44;0m"

--

Patrick TJ McPhee
East York  Canada



Sat, 17 May 2003 13:51:23 GMT  
 Use awk to print syslog output to terminal with colors

Quote:
Tristan writes:
> On my system there's a manual page for "console_codes"
> which details most options for colours.

Nice... That lays it all out for console mode.  A nice treasure to
have onboard.


Quote:
> [...].In general,
> they start with escape (\033), left bracket ([), then a list of numbers
> separated by semi-colons (;), and finishing with a letter. For screen
> colours, the letter is m. The numbers can be
>  0 - normal intensity
>  1 - high intensity
>  4 - underline
>  7 - reverse video
>  8 - invisible
>  3n - set foreground colour to n
>  4n - set background colour to n

> n can be from 0 to 7 (try them out to find out which colour is which).

> So, to get high-intensity red on blue:

>  print "\033[31;44;1mFabulous\033[31;44;0m"

Hey, that was the kind of example I needed.

Thanks ...  As you can see, I've moved right on to some really
advanced code...

BEGIN {print "\033[37;1mThis\033[37;0m \
\033[31;1mis\033[31;0m \033[34;1mreally\033[34;0m \
\033[32;1mcool\033[32;0m\033[35;1m!\033[35;0m"}

hehe  : )  Right up there with painting mustaches on billboards



Sat, 17 May 2003 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Outputting info from awk and using the info to name the awk output file

2. redirecting print output to variable name in awk

3. Copy files using AWK's output

4. using awk to format ifconfig -a output

5. PRINT PREVIEWER FREEWARE - FormView - Views HP PCL Print Output / Prints PCL to ANY WINDOWS PRINTER

6. run awk output thru tee inside awk

7. How to get colors to print on a color printer

8. how print output to screen and output file

9. most lean way to set terminal colors

10. Terminal-based text editor with color syntax hilighting

11. Summer '87 Print Output To Print Manager??

12. output terminal connection inside a while loop

 

 
Powered by phpBB® Forum Software