Monday, June 7, 2010

How to get an absolute value

Some times when we calculating difference we don't want to show the negative value. What we are interested in is only the difference. so here is the command.


prasad@mac:~# absolute_value=-123
prasad@mac:~# echo ${absolute_value#-}
123

You can use this in any shell script.

Tuesday, May 11, 2010

On the Fly zip unzip mysql Backup

mysqldump -u root -ppassword RECEIPTS BlockedNumbersTable | bzip2 -9 | ssh host0119 "bzip2 -d > /mnt/data1/prasad.sql"

Tuesday, March 9, 2010

Vim Syntax

Some times it is observe that vim syntax is not working by default when you install the vim. To git rid of this create the ~/.vimrc file in your home directory with following context

syntax on

thats it. you are done. next time it will automatically support syntax and follow the appropriate coloring information while you do scripting in vim.

Monday, December 14, 2009

Extract Last Field

You can use 'cut' to extract the last field of a line if you know how many fields there are, eg:
field=`cut -d: -f8 file`

But if you don't know the maximum number of fields or the number of fields per line are not consistent, awk can come to the rescue. awk has the inbuilt variable NF for the number of fields. By using this variable we can use it to extract the last field by using:

field=`awk -F: '{print $NF}'`

or you can use calculations to retrieve any field relative to the last field. For example to retrieve the second last field, use:

field=`awk -F: '{print $(NF-1)}'`

Thursday, October 29, 2009

Making current directory available on HTTP

python -m SimpleHTTPServer

Serve current directory tree at http://$HOSTNAME:8000/

COMMANDLINEFU.COM

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Monday, July 13, 2009

Grep Tips(color=always)

Do the following while using grep in future.

cat httpd.conf | grep --color=always httpd