• About Me!!!
  • Its Me!!!

Mani's Weblog

~ Naangalum Sindhippomla!!!

Mani's Weblog

Monthly Archives: August 2013

Problem with grep colors….

01 Thursday Aug 2013

Posted by Mani in Technical

≈ Leave a comment

Tags

grep, lax, Linux

Build-up

Today was a good day for me. Was facing an issue for a looooong time.. Searched the web a loooooooot.. But could not find anything that could help me fix it.

Had to write a shell script today that has to do with grep/awk and suddenly hit upon an issue.  Immediately, I felt that,  Yes!! Today Im going to solve my long pending issue.

My loong pending issue:

I am using a java based application. The application is getting invoked using a shell script. One fine day, (especially after I upgraded Ubuntu to 12.04 I guess), that application started failing to start saying that,

Exception in thread “main” java.lang.NoClassDefFoundError: com/zerog/lax/LAX

I started scolding ubuntu black and blue and even thought of moving to a different distro. 🙂

As I could not find any solutions, I did some “intelligent” research/stuff and invoked the class directly with the parameters that the script was passing and somehow managed to get it working. (But still I could not use the command line build functionality)

Today’s Issue:

I did something like grep -n <Text> <My_File> | awk -F : ‘{print $1}’ On executing this, the color on the terminal got changed and when I showed my “intelligence” to the script (added some parameters to awk on a trial and error basis), I suddenly got a box character. This is the same box character I had seen some time when I did my research on the old java tool issue. This is the moment…

Behind the scenes:

What has happened is, loong loong ago, when I did grep, I wanted to highlight the text that I had searched for. So, did some research and came to know that I can export GREP_OPTIONS=”–color=always” to highlight the searched text and updated my /etc/profile.

Looks like, on seeing this option, grep decorates the text with some special characters. May be between \e[ and \e[m (like the ones mentioned here) So, when that text goes to awk, it thinks that these characters are also regular characters (my input) and starts cutting it. Looks like it had cut between the starting and ending decorators and that resulted in the change of color on my terminal.  On seeing the colors, I realized that the GREP_OPTIONS is the culprit and when I unset it, my script started working fine.

During my rnd today, as I had got the “gift” box and realized that, if I unset the GREP_OPTIONS environment variable, my long pending issue will also be resolved. And attempting that, gave birth to this blog. 🙂

Subscribe

  • Entries (RSS)
  • Comments (RSS)

Archives

  • January 2017
  • November 2016
  • November 2015
  • October 2015
  • June 2015
  • May 2015
  • March 2015
  • January 2015
  • December 2014
  • November 2014
  • October 2014
  • September 2014
  • August 2014
  • July 2014
  • May 2014
  • January 2014
  • November 2013
  • October 2013
  • September 2013
  • August 2013
  • May 2013
  • December 2012
  • March 2012
  • January 2012
  • May 2011
  • April 2011
  • October 2010
  • August 2010
  • July 2010
  • June 2010
  • April 2010
  • February 2010
  • January 2010
  • December 2009
  • August 2009
  • June 2009
  • May 2009
  • March 2009
  • December 2008
  • September 2008
  • July 2008
  • June 2008
  • January 2008
  • November 2007
  • October 2007
  • September 2007
  • July 2007
  • May 2007
  • February 2007
  • December 2006
  • November 2006
  • October 2006
  • July 2006
  • June 2006
  • May 2006
  • March 2006
  • February 2006
  • January 2006
  • November 2005
  • October 2005
  • September 2005

Categories

  • Computers
  • Games
    • Candycrush
  • Personal
  • Review
    • Book
    • Movie
    • Software
  • Science
  • Social
    • Culture
  • Sports
    • Cricket
    • Tennis
  • Tamil
  • Technical
    • Android
    • Linux
  • Technology
  • Uncategorized

Meta

  • Register
  • Log in

Create a free website or blog at WordPress.com.

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy