Monday, July 15, 2013

A Python script to execute Python code like "perl -ne"

I wrote a small utility script that can be used to run a small snippet of Python code like "perl -ne". I find it very useful for my needs. Hope it helps you too. Any suggestions welcome.
You can find the script as a gist here.

Setting the terminal window title - version 2

I had earlier written a small snippet about setting the window title from command line. Based on my experience, I felt that I could make it a lot simpler. Here is version of the same function.

function wtitle {
    if [ -z "$ORIG_PS1" ] ; then
    export PS1="\[\033]0;$1 - \u@\h:\w\007\]$ORIG_PS1"

Wednesday, July 03, 2013

A rarely used but very useful option in grep

I usually do a lot of log analysis. I search for patterns in multiple files in multiple hosts. Then I collate the result and do processing on the result lines. A sample output looks like:
/tmp/input1.txt: line containing pattern
/tmp/input2.txt: another line containing pattern
 As it turns out, I don't need the file names in the grep result. I always used to remove the file name prefixes using a Perl one-liner. Silly me!

I was pretty sure that this was a common problem and it must have been solved already. When I referred to the man page of grep, I came across this gem: -h. If you specify this option, grep will not prefix each line with a the file name.

There is also -H option which will prefix each line with a filename even if you are searching in only one file.