~ Naangalum Sindhippomla!!!

Monthly Archives: August 2013

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,

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. 🙂