Simple & useful: [Many times i forfot this trick]
[mandy ~]$ echo $v1
75
[mandy ~]$ awk -F "|" ' { print $'"$v1"' } ' file_name
mandar
mpande
mp
[mandy ~]$ sed 's/'"$old_val"'/'"$new_val"'/g' file_name
Wednesday, July 18, 2012
variables inside awk print and sed
Monday, July 9, 2012
XML Pull Parser
Found a very good article/link in XML Parsing: Need to check this PullXML Parser thing is available with Perl/Python ? This kind of parsing seems to be really faster, efficient than SAX [Off course faster/better than DOM :)]. XML Pull Parser . http://www.bearcave.com/software/java/xml/xmlpull.html
Tuesday, May 22, 2012
Monday, May 21, 2012
Steps to create git repository on RHEL 5.x system :
rpm -Uvh http://repo.webtatic.com/yum/centos/5/latest.rpm
yum install --enablerepo=webtatic git-all
git
mkdir src
cd src/
git init
cp ../savecmdlog.pl.bak savecmdlog.pl
git
git status
git add savecmdlog.pl
git commit
git config --global user.name "Manas"
git config --global user.email manas_khandeshe@symantec.com
git commit --amend --reset-author
git log
git diff
git commit -a -m 'hard coding of sql statements'
Thursday, May 17, 2012
Tuesday, May 8, 2012
Monday, May 7, 2012
validation for 5GB free space in shell for all platforms
Simple but very useful:
#-------------------------------
# Validation for 5GB free space.
#-------------------------------
#AIX OS
if [ `uname` = "AIX" ]
then
if [ `df -g $op_path | awk ' { print $2 } ' | tail -1` -lt 5 ]
then
echo "Minimum of 5GB of free space should be presnt at $op_path to run the script"
exit
fi
fi
#HP-UX
if [ `uname` = "HP-UX" ]
then
val=`bdf $op_path | awk ' { print $4 } ' | tail -1`
val_gb1=`echo "scale=2; $val/1024" | bc`
val_gb=`echo "scale=2; $val_gb1/1024" | bc`
#if [ $val_gb \< 5 ]
if [ $val_gb -lt 5 ]
then
echo "Minimum of 5GB of free space should be presnt at $op_path to run the script"
exit
fi
fi
#SunOS
if [ `uname` = "SunOS" ]
then
val=`df -k $op_path | awk ' { print $4 } ' | tail -1`
val_gb1=`echo "scale=2; $val/1024" | bc`
val_gb=`echo "scale=2; $val_gb1/1024" | bc`
#if [ $val_gb \< 5 ]
if [ $val_gb -lt 5 ]
then
echo "Minimum of 5GB of free space should be presnt at $op_path to run the script"
exit
fi
fi
#Linux
if [ `uname` = "Linux" ]
then
val=`df -k $op_path | awk ' { print $4 } ' | tail -1`
val_gb1=`echo "scale=2; $val/1024" | bc`
val_gb=`echo "scale=2; $val_gb1/1024" | bc`
if [ $val_gb \< 5 ]
then
echo "Minimum of 5GB of free space should be presnt at $op_path to run the script"
exit
fi
fi
Monday, April 30, 2012
How to use "Like" and "In" together in MySQL ?
Simple and very useful:
SELECT * FROM tablename WHERE column LIKE 'M510%'
OR column LIKE 'M615%'
OR column LIKE 'M515%'
OR column LIKE 'M612%';
Monday, April 16, 2012
Constructor overloading in Perl
Base Class:
-----------
#!/usr/bin/perl
use strict;
use Data::Dumper;
#write package name:
package Person;
#write constructor
sub new
{
#declare => hash & bless it and return it.
my($class)=shift;
my($self)={
_name=>shift,
_sname=>shift,
};
bless $self, $class;
return $self;
}
1;
Derived class:
--------------
#!/usr/bin/perl
#define package:
package Employee;
use strict;
use Data::Dumper;
#use parent class
use Person;
#Define ISA
our @ISA = qw(Person);
#Define constructor with child and parent both:
sub new
{
my($class)=@_;
my($self)=$class->SUPER::new($_[1],$_[2]);
$self->{_id} = $_[3];
$self->{_sal} = $_[4];
return ($self);
}
1;
Program:
--------
use strict;
use Data::Dumper;
use Person;
use Employee;
sub main
{
my($obj)=Employee->new("mandar","pande","111515","1");
print "$obj->{_name}\n";
print "$obj->{_sname}\n";
print "$obj->{_id}\n";
print "$obj->{_sal}\n";
}
main();
Multithreading in Perl
Found few good links with examples:
http://pages.swcp.com/~breadfan/threads/threads_shared.html
http://migo.sixbit.org/papers/Perl_Threads/slide-00.html
http://pages.swcp.com/~breadfan/threads/threads_shared.html
http://migo.sixbit.org/papers/Perl_Threads/slide-00.html
Monday, April 9, 2012
Awesome use case for tr command.
Use case : Remove all whitespaces but one from the output of any of the unix command ( for e. g. free -m )
Current command output:
[root@host ~]free -m
total used free shared buffers cached
Mem: 16046 15779 267 0 20 14269
-/+ buffers/cache: 1489 14557
Swap: 4000 0 4000
with tr,
[root@host ~]free -m |tr -s " "
total used free shared buffers cached
Mem: 16046 15778 268 0 20 14269
-/+ buffers/cache: 1488 14558
Swap: 4000 0 4000
where,
-s : replace each input sequence of a repeated character that is listed in SET1( in our case it is space character " " ) with a single occurrence of that character.
In this way we can get output with only one space character as a delimiter.
Use case : Remove all whitespaces but one from the output of any of the unix command ( for e. g. free -m )
Current command output:
[root@host ~]free -m
total used free shared buffers cached
Mem: 16046 15779 267 0 20 14269
-/+ buffers/cache: 1489 14557
Swap: 4000 0 4000
with tr,
[root@host ~]free -m |tr -s " "
total used free shared buffers cached
Mem: 16046 15778 268 0 20 14269
-/+ buffers/cache: 1488 14558
Swap: 4000 0 4000
where,
-s : replace each input sequence of a repeated character that is listed in SET1( in our case it is space character " " ) with a single occurrence of that character.
In this way we can get output with only one space character as a delimiter.
How to execute a script with exit status from bash shell in background ?
=>
[root@host ~]cat /tmp/a
#!/bin/bash
sleep 1
echo 1% complete
sleep 1
echo 10% complete
sleep 1
echo 100% complete
exit 12
[root@host~] (/tmp/a > /tmp/stdout;echo $? > /tmp/ret) &
Verification :
========
[root@puneoshub ~](/tmp/a > /tmp/stdout;echo $? > /tmp/ret) & <----------- way to execute.
[1] 24110
[root@puneoshub ~]
[1]+ Done ( /tmp/a > /tmp/stdout; echo $? > /tmp/ret )
[root@puneoshub ~]cat /tmp/stdout /tmp/ret
1% complete < ----- STDOUT
10% complete
100% complete
12 < ----- RETURN
=>
[root@host ~]cat /tmp/a
#!/bin/bash
sleep 1
echo 1% complete
sleep 1
echo 10% complete
sleep 1
echo 100% complete
exit 12
[root@host~] (/tmp/a > /tmp/stdout;echo $? > /tmp/ret) &
Verification :
========
[root@puneoshub ~](/tmp/a > /tmp/stdout;echo $? > /tmp/ret) & <----------- way to execute.
[1] 24110
[root@puneoshub ~]
[1]+ Done ( /tmp/a > /tmp/stdout; echo $? > /tmp/ret )
[root@puneoshub ~]cat /tmp/stdout /tmp/ret
1% complete < ----- STDOUT
10% complete
100% complete
12 < ----- RETURN
Sunday, April 8, 2012
Perl Regex continue......
In order to match a string in a multiline string use the 'm' modifier.
For Ex:
The string is: "Hello wassup\n How u doing\n goaway"
and we have to match "How u doing", it cant be match the same way as perl doesn't check after newline if we dont tell it to.
So use:
$string =~ /How u doing/m
Continue with the perl regex ....... cheers!!!
For Ex:
The string is: "Hello wassup\n How u doing\n goaway"
and we have to match "How u doing", it cant be match the same way as perl doesn't check after newline if we dont tell it to.
So use:
$string =~ /How u doing/m
Continue with the perl regex ....... cheers!!!
Wednesday, April 4, 2012
MySQL Benchmark
How my server is performing ?
===========================
No matter the result of the expression, the result of benchmark() will always be 0. The purpose of benchmark() is not to retrieve the result of the expression but to see how long it takes to repeat the expression for a specific number of times. For example, the following command executes the expression 10 + 10 one million times:
mysql> SELECT BENCHMARK(1000000,10+10);
+--------------------------+
| BENCHMARK(1000000,10+10) |
+--------------------------+
| 0 |
+--------------------------+
1 row in set (0.14 sec)
===========================
No matter the result of the expression, the result of benchmark() will always be 0. The purpose of benchmark() is not to retrieve the result of the expression but to see how long it takes to repeat the expression for a specific number of times. For example, the following command executes the expression 10 + 10 one million times:
mysql> SELECT BENCHMARK(1000000,10+10);
+--------------------------+
| BENCHMARK(1000000,10+10) |
+--------------------------+
| 0 |
+--------------------------+
1 row in set (0.14 sec)
Tuesday, April 3, 2012
Sunday, April 1, 2012
Comparison of Different SQL Implementation
Guys,
Found a comprehensive research.
Check out this article, it expalins quite interesting things about diff DB's and also a comparison between them, which is a most faq in interviews.
http://troels.arvin.dk/db/rdbms/
Found a comprehensive research.
Check out this article, it expalins quite interesting things about diff DB's and also a comparison between them, which is a most faq in interviews.
http://troels.arvin.dk/db/rdbms/
Subscribe to:
Posts (Atom)