GREP_COLORS – change the colors in the GREP output.

2019-04-22 4 min read Bash Linux

Today we will look at the variable GREP_COLORS. This variable determines the colour that is used with the grep command. You can look at the man page of the grep command to see what the various options mean. Here is the excerpt from the man command:

GREP_COLORS
          Specifies the colors and other attributes used to highlight various  parts  of  the
          output.   Its  value  is  a  colon-separated  list of capabilities that defaults to
          ms=01;31:mc=01;31:sl=:cx=:fn=35:ln=32:bn=32:se=36  with  the  rv  and  ne   boolean
          capabilities omitted (i.e., false).  Supported capabilities are as follows.

          sl=    SGR  <a class="zem_slink" title="Substring" href="http://en.wikipedia.org/wiki/Substring" rel="wikipedia">substring</a>  for  whole  selected lines (i.e., matching lines when the -v
                 command-line option is omitted, or non-matching lines when -v is specified).
                 If however the boolean rv capability and the -v command-line option are both
                 specified, it applies to context matching lines  instead.   The  <a class="zem_slink" title="Default (finance)" href="http://en.wikipedia.org/wiki/Default_%28finance%29" rel="wikipedia">default</a>  is
                 empty (i.e., the terminal's default color pair).

          cx=    SGR  substring for whole context lines (i.e., non-matching lines when the -v
                 command-line option is omitted, or matching lines when -v is specified).  If
                 however  the  boolean  rv capability and the -v command-line option are both
                 specified, it applies to selected non-matching lines instead.   The  default
                 is empty (i.e., the terminal's default color pair).

          rv     <a class="zem_slink" title="Boolean data type" href="http://en.wikipedia.org/wiki/Boolean_data_type" rel="wikipedia">Boolean  value</a>  that  reverses  (swaps)  the  meanings  of  the  sl= and cx=
                 capabilities when the -v command-line option is specified.  The  default  is
                 false (i.e., the capability is omitted).

          mt=01;31
                 SGR  substring  for  matching  <a class="zem_slink" title="Empty set" href="http://en.wikipedia.org/wiki/Empty_set" rel="wikipedia">non-empty</a>  text in any matching line (i.e., a
                 selected line when the -v command-line option is omitted, or a context  line
                 when  -v  is specified).  Setting this is equivalent to setting both ms= and
                 mc= at once to the same value.  The default is a bold  red  text  foreground
                 over the current line background.

          ms=01;31
                 SGR substring for matching non-empty text in a selected line.  (This is only
                 used when the -v command-line option is omitted.)  The effect of the sl= (or
                 cx=  if  rv) capability remains active when this kicks in.  The default is a
                 bold red text foreground over the current line background.

          mc=01;31
                 SGR substring for matching non-empty text in a context line.  (This is  only
                 used  when  the -v command-line option is specified.)  The effect of the cx=
                 (or sl= if rv) capability remains active when this kicks in.  The default is
                 a bold red text foreground over the current line background.

          fn=35  SGR  substring  for file names prefixing any content line.  The default is a
                 magenta text foreground over the terminal's default background.

          ln=32  SGR substring for <a class="zem_slink" title="Line number" href="http://en.wikipedia.org/wiki/Line_number" rel="wikipedia">line numbers</a> prefixing any content line.  The default is a
                 green text foreground over the terminal's default background.

          bn=32  SGR substring for byte offsets prefixing any content line.  The default is a
                 green text foreground over the terminal's default background.

          se=36  SGR substring for separators that are inserted between selected line  fields
                 (:),  between context line fields, (-), and between groups of adjacent lines
                 when nonzero context  is  specified  (--).   The  default  is  a  cyan  text
                 foreground over the terminal's default background.

          ne     Boolean  value that prevents clearing to the <a class="zem_slink" title="Newline" href="http://en.wikipedia.org/wiki/Newline" rel="wikipedia">end of line</a> using Erase in Line
                 (EL) to Right (\33[K) each time a colorized item ends.  This  is  needed  on
                 terminals on which EL is not supported.  It is otherwise useful on terminals
                 for which the back_color_erase (bce) boolean terminfo  capability  does  not
                 apply,  when  the  chosen  highlight colors do not affect the background, or
                 when EL is too slow or causes too much flicker.  The default is false (i.e.,
                 the capability is omitted).

Continue reading

create text tables from delimited files.

2013-07-12 1 min read Bash Fedora

To create simple text tables to paste in emails or to use in any other document where you want to show a table, here is something that you can use. There is a perl module which provides “tablify“. And here is how to use it:

sudo yum install perl-Text-RecordParser

This will install a command “tablify” that you can use in number of ways. Here is a simple example to use it. You can read the man pages to see how you can use it.

Continue reading

Rekursive Grep on Solaris or AIX Systems without GNU egrep -r funcionality

2011-12-16 1 min read Learning Solaris

If you work regularly on a Solaris or systems which do not have the “-r” (recursive grep) for grep, then you know what a lifesaver this command can be.

Here is one from command line fu:

find . -type f -exec awk '/linux/ { printf "%s %s: %s\n", FILENAME, NR, $0; }' {} \;

The benefit of using awk here is that you can print the line number also 🙂

Continue reading

bash regular expressions

2011-02-06 1 min read Bash

Here are some quick links on bash regular expressions, pretty good links to bookmark, if you use, regular expressions in bash regularly. I especially like the tldp link at number 3.

http://www.linuxjournal.com/content/bash-regular-expressions
http://www.ibm.com/developerworks/library/l-bash.html
http://tldp.org/LDP/abs/html/parameter-substitution.html#VARMATCH
http://wellington.pm.org/archive/200005/codegen/index9.htm

Enhanced by Zemanta

Building a Finite State Machine Using DFA::Simple

2010-12-15 11 min read Perl

http://www.perl.com/pub/2004/09/23/fsms.html

Building a Finite State Machine Using DFA::Simple By Bill Ruppert on September 23, 2004 12:00 AM I am converting some articles from MS Word to HTML by hand. I often use bulleted outlines so I face a lot of work creating lists with nested sub-lists. It didn’t take opening and closing many

and

  • tags to realize I wanted to automate the task. It’s very easy to use filters with my text editor and I’ve written several in Perl to speed up my HTML formatting. I decided to create a filter to handle this annoying chore. After a little thought I decided the logic involved was just tricky enough to use a finite state machine (FSM) to keep things straight.

    Continue reading

Handy one-liners for SED

2010-09-14 0 min read Bash Linux
\"A
Image via Wikipedia

Here are some links to sed one liners, pretty useful if you want to use the power of sed.

<a href="http://www.freearchive.org/o/dd1ebea77f64bdef5982d50e868990202b0bf6f21b42e26ebb0ab1011d6ce546">http://www.freearchive.org/o/dd1ebea77f64bdef5982d50e868990202b0bf6f21b42e26ebb0ab1011d6ce546

<a href="http://www.unixguide.net/unix/sedoneliner.shtml">http://www.unixguide.net/unix/sedoneliner.shtml
<a href="http://sed.sourceforge.net/sed1line.txt">http://sed.sourceforge.net/sed1line.txt <a href="http://www.thegeekstuff.com/2010/06/bash-array-tutorial/">

<a href="http://www.thegeekstuff.com/2010/06/bash-array-tutorial/">http://www.thegeekstuff.com/2010/06/bash-array-tutorial/<h6 class="zemanta-related-title" style="font-size: 1em;">Related articles by Zemanta <ul class="zemanta-article-ul"> <li class="zemanta-article-ul-li"><a href="http://www.ibm.com/developerworks/linux/library/l-sed1.html">imabonehead: Common threads: Sed by example, Part 1 (ibm.com) <li class="zemanta-article-ul-li"><a href="http://www.thegeekstuff.com/2009/11/unix-sed-tutorial-append-insert-replace-and-count-file-lines/">imabonehead: Unix Sed Tutorial: Append, Insert, Replace, and Count File Lines (thegeekstuff.com) <div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Enhanced by Zemanta" href="http://www.zemanta.com/"><img class="zemanta-pixie-img" style="border: medium none; float: right;" src="http://img.zemanta.com/zemified_e.png?x-id=be4d9a3b-c27c-46eb-8b76-2a1aa1900a4e" alt="Enhanced by Zemanta" /><span class="zem-script more-related pretty-attribution">

Continue reading

regular expression, sed and grep tuturials and tricks.

2010-06-17 1 min read Linux

Simply a great one page article on sed and use of regular expressions.

<a href="http://almirkaric.com/2009/07/15/sed-and-grep-tips/" target="_blank">http://almirkaric.com/2009/07/15/sed-and-grep-tips/

Older posts