Aug 25, 2012

Where can I get mustache from?

All these days Chinni had not observed my mustache. But all of a sudden today, the question popped up. She notices my mustache and asks what is this ?

I replied its called "mustache", well now-a-days most of the times I talk to her in English.

Cleverly Chinni pops another question "Where did you get it from?"

What do I answer?

Aug 24, 2012

Unix Shell scripting

This post was badly required, just for me. Every time I have a write a script, I google. Its difficult to remember the various options of various commands. And most of the time its search, extract or replace. So here it goes

1. To split a string and extract a value
value=$(echo $line | awk '{split($0, splitValues, " ");  print splitValues[1] }')

  • Input to split is the value in the variable line.
  • split command splits the string, executing the regular expression within quotes and stores in an array splitValues.
  • print splitValues[1] returns the first element in array splitValues
  • If you dont want to store the value then  echo $line | awk '{split($0, splitValues, " ");  print splitValues[1] }' will print it on the console
2. Find a matching pattern in a file and extract them to another file
grep -n 'match this' test.log > result.log

  • grep searches the complete file test.log for the string mentioned in quotes
  • all the lines which matches the pattern are extracted to result.log
  • -n prefixes the line number of every match (-n is optional)
3.  Print last few lines from a file
tail -n
  • This command extract the number of lines of the specified file and prints it on the console
  • The output can always be redirected to a file tail -10 output.txt > subset.txt
4. Executing an sql in shell script - There are few steps to achieve this
  • Write a sql and store it in a file, say SelectQuery.sql
  • The shell script to connect to database and execute the query in SelectQuery.sql looks something like this
 #!/bin/bash
sqlplus -s -l /@  << EOF >> output.txt
@SelectQuery.sql
exit
EOF

while read line
do
    echo $line
done <  output.txt

errorCode=$?    # checks if the last operation (sqlplus) was completed successfully or not

if [ ${errorCode} -ne 0 ]
then
echo "SQLPlus was unable to connect the DB with the supplied credentials"
else
echo  "SQLPlus was connected successfully"
fi


So what does this script do ?
  • Connects to database using sqlplus command 
  • output.txt is where the results of the query will be stored
  • @SelectQuery.sql actually executes the query
  • The while loop, iterates through each lines in the output.txt and prints them on console
  • A small check to display an errors at the end

Aug 17, 2012

Chinni's advice

I was dropping Chinni to school today morning. While driving I coughed couple of times and Chinni instantaneously gives me an advice

"ಪಪ್ಪಾ , ಐಸ್ ಕ್ರೀಂ ತಿನ್  ಬೇಡ, ಕೆಮ್ಮು ಬರುತ್ತೆ"

meaning "Pappa, don't eat ice cream, you will get cough".

How clever!!!

Aug 1, 2012

A compliment from Chinni

I am wearing a new T-shirt today. Chinni was ready to go to school and I was ready to drop her. She noticed the new shirt and comments "ಚೆನ್ನಾಗಿದೆ ", meaning its good.

Where as my dear wife didn't even noticed that. Well, yday even though she had noticed, there wasn't a comment.