Sponsored Content
Top Forums UNIX for Beginners Questions & Answers How to add 'color' in a grep? Post 303028478 by gull04 on Wednesday 9th of January 2019 05:21:07 AM
Old 01-09-2019
Hi Guys,

Just for reference, here is a little shell script that I sometimes use to check whats available if I want to use colo(u)r.

Code:
#!/bin/bash
##################################################################################
#
# Test script to show the available colours on a monitor, this allows the generation
# of highlighted output from ordinary shell scripts - to be integrated with the
# logger shell to make pretty output.
#
##################################################################################

T='XXX'   # The test text

echo -e "\n                 40m     41m     42m     43m\
     44m     45m     46m     47m";

for FGs in '    m' '   1m' '  30m' '1;30m' '  31m' '1;31m' '  32m' \
           '1;32m' '  33m' '1;33m' '  34m' '1;34m' '  35m' '1;35m' \
           '  36m' '1;36m' '  37m' '1;37m';
  do FG=${FGs// /}
  echo -en " $FGs \033[$FG  $T  "
  for BG in 40m 41m 42m 43m 44m 45m 46m 47m;
    do echo -en "$EINS \033[$FG\033[$BG  $T  \033[0m";
  done
  echo;
done

Feel free to use;

Regards

Gull04
These 2 Users Gave Thanks to gull04 For This Post:
 

5 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

color highlighting with 'more','grep' and 'vi'

Hi all, i would to find out how can i turn on color hightlighting with the 'more' command. When i view a big file, i tend to use the 'more' command and i would search for a interested string with the '/' command. Something the search returns more than 1 line found on the screen, how can i... (0 Replies)
Discussion started by: new2ss
0 Replies

2. UNIX for Dummies Questions & Answers

Grep ruins color

When I run: git branch -a I git a nice green and red colored output, but if I pipe the above command through grep: git branch -a | grep -v "master" I lose my colored output. Is there a way around this? (2 Replies)
Discussion started by: blasto333
2 Replies

3. Shell Programming and Scripting

Add color in CSV cells

hi, i have text file that file contains below information. Name,Roll,Mark,Total Sivasankar,2120,89,410 Raja,2212,87,425 i need to convert text file to CSV file also the heading(Name,Roll,Mark,Total) font should be BOLD and color should be RED. how can i set fonts in csv (5 Replies)
Discussion started by: rsivasan
5 Replies

4. UNIX for Dummies Questions & Answers

How to add '--color' with pipes?

Hi guys - I was wondering if there is a way to add 'color' to a grep I do like this below: fgrep -i "XYZ-1124354-P" mylog.log | tr "\001" " " | sed G (7 Replies)
Discussion started by: DallasT
7 Replies

5. Shell Programming and Scripting

Add Color To html Doc

I have a script which converts a .csv file to html nicely. Trying to add 3 colors, green, yellow and red to the output depending upon the values in the cells. Tried some printf command but just can't seem to get any where. Any ideas would be appreciated. nawk 'BEGIN{ FS="," print ... (7 Replies)
Discussion started by: jimmyf
7 Replies
colormake(1)						      General Commands Manual						      colormake(1)

NAME
colormake - color wrapper for make(1) SYNOPSIS
colormake [ --short ] ... DESCRIPTION
colormake acts as a wrapper around make(1) to ease reading the output by colorizing it. OPTIONS
The --short option instructs colormake to truncate lines so they do not wrap. All other options will be passed unmodified to make(1). USAGE
To change a makefile to use colormake, you may change the path at the top which normally reads #!/usr/bin/make to #!/usr/bin/colormake. Alternately, you may type colormake whenever you would normally type make when compiling programs. Colormake is also available using the alternate names which enable piping through less (clmake), truncated output so lines do not wrap (colormake-short), or both (clmake-short). FILES
The configuration files are Perl scripts included by colormake.pl. The defaults values are (from colormake.pl itself): # Some useful color codes, see end of file for more. # $col_black = "33[30m"; $col_red = "33[31m"; $col_green = "33[32m"; $col_yellow = "33[33m"; $col_blue = "33[34m"; $col_magenta = "33[35m"; $col_cyan = "33[36m"; $col_ltgray = "33[37m"; $col_norm = "33[00m"; $col_background = "33[07m"; $col_brighten = "33[01m"; $col_underline = "33[04m"; $col_blink = "33[05m"; # Customize colors here... # $col_default = $col_ltgray; $col_gcc = $col_magenta . $col_brighten; $col_make = $col_cyan; $col_filename = $col_yellow; $col_linenum = $col_cyan; $col_trace = $col_yellow; $col_warning = $col_green; $tag_error = ""; $col_error = $tag_error . $col_yellow . $col_brighten; $error_highlight = $col_brighten; For use with gnome-terminal I have the following configuration in my $HOME/.colormakerc file: $col_default = $col_black; $col_gcc = $col_magenta; $col_filename = $col_blue; $col_linenum = $col_cyan; $col_error = $tag_error . $col_red . $col_brighten; /usr/share/colormake/colormake.rc System-wide configuration file for colormake. $HOME/.colormakerc Personal configuration file for colormake. HISTORY
/usr/bin/colormake was formerly named /usr/bin/cmake but had to be renamed because of a name clash. AUTHORS
Bjarni R. Einarsson is the author of colormake. This manual page was written for the Debian GNU/Linux distribution because the original program does not have a manual page. This manual page was written by Joe Wreschnig <piman@sacredchao.net> and updated by Ludovic Rousseau <rousseau@debian.org>, for the Debian GNU/Linux system (but may be used by others). SEE ALSO
make(1), clmake(1) July 2nd, 2001 colormake(1)
All times are GMT -4. The time now is 07:46 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy