We have moved to www.dataGenX.net, Keep Learning with us.

Sunday, January 15, 2012

bc command : tips & tricks

bc stands for bench calculator
Here are some examples of bc command :

a) addition
$ echo '57+43' | bc 100

b) subtraction
$ echo '57-43' | bc 14

c) multiplication
$ echo '57*43' | bc 2451

The scale variable determines the number of digits which follow the decimal point in your result. By default, the value of the scale variable is zero.

d) division
$ echo 'scale=25;57/43' | bc 1.3255813953488372093023255

Friday, January 13, 2012

Export , Import & Load utility in DB2 : Part - 3

LOAD Operation :: The LOAD utility write pages of data directly to the database instead of using SQL statements & does not record changes in any log files. This means that LOAD operation is faster than IMPORT transaction. However if LOAD transaction failes , the data cant be reloaded by performing a roll- forward recovery operation. To compensate for this , we have to create a backup copy of all data that is loaded so that it can be reloaded if necessary.

Syntax ::
LOAD <CLIENT> FROM [Filename of [DEL | ASC | IXF] | Pipename | Device| CursorName of Cursor , ...]
<LOBS FROM [LOBpath , ..]>
<MODIFIED BY [Modifier , ..]>
<SAVECOUNT [SaveCount]>
<ROWCOUNT [RowCount]>
<WARNINGCOUNT [WarningCount]>

(i) LOAD from Cust.ixf of ixf messages load_msgs.txt insert into customers 

Export , Import & Load utility in DB2 : Part -2

IMPORT UTILITY To  import data into database

IMPORT from [filename] of [asc|del|wsf|ixf]
<lobs from [lobpath,...]>
<modified by [modifier,..]>
INTO [TABLENAME] <([ColumnName,....])>

CREATE :-  if this option is used , table is first created in the database before any data is imported. This option can only be used with IXF files.
INSERT:-  new data is added to the table without altering any of the existing data
INSERT_UPDATE:- new data is either added to the table or existing records are updated
REPLACE :- All existing data is deleted from the table before the new data is added.The table needs to be exist already
REPLACE_CREATE :- the table is first created if it does not already exist. Otherwise existing data is deleted from the table before new data is added.This option can only be used with IXF files. Also this option cant be used if the target table is a parent table that is referenced by foreign key.

eg: (i) import from cust.ixf of ixf insert into customers
(ii) import from cust.ixf of ixf lobs from c:\lobs modified by lobsinfile replace into customers
(iii)The following example shows how to import the table MOVIETABLE from the input file delfile1, which has data in the DEL format:

db2 import from delfile1 of del
modified by dldel|
insert into movietable (actorname,description,url_making_of,
url_movie) datalink specification (dl_url_default_prefix
"http://narang"), (dl_url_replace_prefix "http://bomdel"
dl_url_suffix ".mpeg")


  1.  The table has four columns:

       actorname              VARCHAR(n)
       description            VARCHAR(m)
       url_making_of          DATALINK (with LINKTYPE URL)
       url_movie              DATALINK (with LINKTYPE URL)

 2.   The DATALINK data in the input file has the vertical bar (|) character as the sub-field delimiter.
 3.   If any column value for url_making_of does not have the prefix character sequence, "http://narang" is used.
 4.   Each non-NULL column value for url_movie will get "http://bomdel" as its prefix. Existing values are replaced.
 5.   Each non-NULL column value for url_movie will get ".mpeg" appended to the path. For example, if a column value of url_movie is "http://server1/x/y/z", it will be stored as "http://bomdel/x/y/z.mpeg"; if the value is "/x/y/z", it will be stored as "http://bomdel/x/y/z.mpeg".

Export , Import & Load utility in DB2 : Part -1

Types of External file formats 

Db2 Supports 4 different types of External Files ::
-->Delimited ASCII(DEL)
-->NON Delimited ASCII
-->PC Integrated Exchange Format(IXF) {**Binary Format**}
-->Worksheet Format(WSF) {for exporting a table to Lotus 1-2-3 & Symphony Spreadsheet)

Storing data in External Files ::(3 methods )
1)Name Method : its is used when you export data from DB2 UDB database.its is used when exporting data between DB2 product in IXF format oir when you export data to Lotus products in WSF format.Similarly its used when importing data from Db2 & Lotus products to Db2

2)Location Method : Used with Non Delimited ASC files. Db2 wont support exporting data in this format. So you can only use when importing data.

3)Position method : Its used when importing or exporting files in IXF or DEL format.You an use this method when transferring data between DB2 products in IXF. ALSo you can use it for transferring data between DB2 UDB & other databases that reqire DEL format.

EXPORT UTILITY :: It enables you to Extract data form tables & views in Db2 database in format that can be used by other databse or applications.The files formats are , DEL , IXF, WSF.
==>To use Export Utility u should have SYSADM or DBADM authority or CONTROL or SELECT priveleges on each relevant table

Export to [filename] of [del|wsf|ixf]
<LOBS TO [LOBPath,...]>
<MODIFIED BY [Modifier , ...]>
<METHOD N ([ColumnName, ...])>
[SELECT statement ]

for Eg::
(i) db2 export to myfile.ixf of ixf messages msgs.txt select * from staff     {The following example shows how to export information from the STAFF table in the SAMPLE database to the file myfile.ixf. The output will be in IXF format.}

(ii) db2 export to awards.ixf of ixf messages msgs.txt select * from staff where dept = 20    {The following example shows how to export the information about employees in Department 20 from the STAFF table in the SAMPLE database. The output will be in IXF format and will go into the awards.ixf file.}

(iii)db2 export to myfile.del of del lobs to mylobs/lobfile lobs1, lobs2 modified by lobsinfile select * from emp_photo {The following example shows how to export LOBs to a DEL file: }

(iv) export to products.txt of del select * from products

(v) export to products.txt of del lobs to C:\lobs modified by lobsinfile select * from products

The Unix Time Command : tips & tricks

If you have a program ./prog.e then in the bash/ksh shell you can type this command and the output on the screen details how long the code took to run:
$ time ./prog.e
real   24m10.951s user    6m2.390s sys     0m15.705s

Real time - Elapsed time from beginning to end of program (or wall clock time).The real time is the total  time of execution.
CPU time - Divided into User time and System time.
User time - time used by the program itself and any library subroutines it calls.The user time is the time spent processing at the user/application process level.
System time - time used by the system calls invoked by the program (directly or indirectly).The sys time is the time spent by the system at the system/kernel level.

If the wall clock time is consistently much longer than the total of the system and user time, then the fetching of data to and from hard drives may be taking a good deal of time. In parallel codes, the code may be spending a good deal of time waiting on communication between processors.

By this command you can check your script performance.

happy scripting :-)

Tuesday, January 10, 2012

Script/Code Header

Hi Guys, I am sharing a Script Header or we can say a Code Header
which we can use in our code to provide more proper description of the code.

Please find the link.  download

Saturday, January 07, 2012

du command & tips

Hi folks, Here I am again with some nice nix commands tips/tricks
For this session, I have "du" command.

The du command displays the number of blocks used for files. If the File parameter specified is actually a directory, all files within the directory are reported on. If no File parameter is provided, the ducommand uses the files in the current directory......

$ ls -ls
total 6
 2 -rw-r--r--   1 mjb     group        3 Feb 04 23:31 minutes.txt
 4 -rw-r--r--   1 mjb     group     1201 Feb 04 23:25 note.txt
52 -rwxrwxrwx   1 adm     mqm      50329 Dec 16 08:25 addGLC  

The first column contains the size of the file in 512-byte blocks, and the sixth column gives the size of the file in bytes.
Earlier Unix systems used an allocation unit of 512 bytes. These 512 bytes came to be known as a block. As disk sizes grew, the basic allocation unit was increased to 1024 bytes on most systems (larger on some), but many utilities, such as ls above, still report file sizes or disk use in 512 byte blocks. So, the 3-byte file uses 2 blocks.

$du -a
8       ./.profile
8       ./.vi_history
8       ./.kshrc
8       ./dir1/ccms
The -a flag reports the number of blocks in individual files.

$du -s This displays a summary of the directory size. It is the simplest way to know the total size of the current directory.

Shows the size in default block size (512 byte)
$du ./AUTOTEST/library/init.tcl
56      ./AUTOTEST/library/init.tcl

Shows the size in 1KB block size
$du -k ./AUTOTEST/library/init.tcl
28      ./AUTOTEST/library/init.tcl

Shows the size in 1MB block size
$du -m ./AUTOTEST/library/init.tcl
0.03    ./AUTOTEST/library/init.tcl

Shows the size in 1GB block size
$du -g ./AUTOTEST/library/init.tcl
0.00    ./AUTOTEST/library/init.tcl


a) display the disk usage of all files in KB
$du -ak | sort +nr

b) display the disk usage of largest 10 files in KB
du -ak | sort +nr | head

c)display everything sorted by filesize:
$ du -sk .[A-z]* *| sort -n

d)find top 5 directories, enter :
$ cd /home/user1
$ du -sk * | sort -nr | head -5

Friday, January 06, 2012

tr command & tips

Hi folks, Here I am with some nice nix commands tips/tricks
For this session, I have "tr" command......

tr command
The tr utility translates one set of characters into another. This utility copies the given input to produced the output with substitution or deletion of selected characters. tr abbreviated as translate or transliterate.

The tr command performs three kinds of operations
a) Transforming Characters
b) Deleting Characters Using the -d Flag
c) Removing Sequences Using the -s Flag

a) Transforming Characters
$echo "She is miss universe"  | tr '[a-z]' '[A-Z]'

$echo "She is miss universe"  | tr 'es' '#@'
Sh# i@ mi@@ univ#r@#

Explanation :: the tr command replaces each character contained in String1 from the standard input with the character in the same position in String2.

b) Deleting Characters Using the -d Flag

echo "Shhee iiis misss universeee" | tr -d 's'
Shhee iii mi univereee

Explanation :: the tr command deletes each character contained in String1 from standard input.

c) Removing Sequences Using the -s Flag 

$echo "Shhee iiis misss universeee" | tr -s 's'
Shhee iiis mis universeee

$echo "Shhee iiis misss universeee" | tr -s 'si'
Shhee is mis universeee

Explanation :: the tr command removes all but the first character in any sequence of a character string represented in String1

Thursday, January 05, 2012

Windos Run Commands -- Part 4

To Access…  RunCommand
Phone Dialer dialer
Pinball Game pinball
Power Configuration  powercfg.cpl
Printers and Faxes control printers
Printers Folder printers
Private Character Editor eudcedit
Quicktime (If Installed) QuickTime.cpl
Quicktime Player (if installed) quicktimeplayer
Real Player (if installed) realplay
Regional Settings  intl.cpl
Registry Editor regedit
Registry Editor regedit32
Remote Access Phonebook rasphone
Remote Desktop  mstsc
Removable Storage ntmsmgr.msc
Removable Storage Operator Requests ntmsoprq.msc
Resultant Set of Policy (XP Prof) rsop.msc
Scanners and Cameras sticpl.cpl
Scheduled Tasks control schedtasks
Security Center  wscui.cpl
Services services.msc
Shared Folders fsmgmt.msc
Shuts Down Windows shutdown
Sounds and Audio  mmsys.cpl
Spider Solitare Card Game spider
SQL Client Configuration  cliconfg
System Configuration Editor sysedit

dos2nix and nix2dos script : file conversion from unix to/from dos

Hi Guys, Here I am sharing 2 small script which you can use to convert files format after transferring the files from unix to dos or vice versa. This extra carriage return can be removed or inserted with two simple scripts,
you can create 2 executable script files from these code and njoy the nix :-)

There is 2 commands are already there "unix2dos" and "dos2unix" but all shells are not
supporting them. ( see here ) So here it is : ....

dos2nix -- download
# dos2nix
# removes an extra carriage return in a dos/widows
# text file so that end of line matches
# the Unix convention.
# Also removes a control-Z at end of file
# working same as dos2unix command

echo "usage: crlf2lf dos.txt unix.txt

if [ $# != 2 ]

sed 's/^M//g
s/^Z//g' <$1 >$2

nix2dos -- download
# nix2dos
# adds an extra carriage return in a unix
# text file so that end of line matches
# the Windows/DOS convention
# working same as unix2dos command

echo "usage: nix2dos nix.txt dos.txt"

if [ $# != 2 ]

sed 's/$/^M/g' <$1 >$2

njoy the simplicity.......

Tuesday, January 03, 2012

Special shell variables : Unix/Linux

Special shell variables  There are some variables which are set internally by the shell and which are available to the user:

$1 - $9
these variables are the positional parameters.
the name of the command currently being executed.
the number of positional arguments given to this invocation of the shell.
the exit status of the last command executed is given as a decimal string.  When a command impletes successfully, it returns the exit status of 0 (zero), otherwise it returns a non-zero exit status
$$             the process number of this shell - useful for including in filenames, to make them unique.
the process id of the last command run in the background.
the current options supplied to this invocation of the shell.
a string containing all the arguments to the shell, starting at $1.
same as above, except when quoted.

Tips ::
$* and $@ when unquoted are identical and expand into the arguments.
"$*" is a single word, comprising all the arguments to the shell, joined together with spaces. For example '1 2' 3 becomes "1 2 3".
"$@" is identical to the arguments received by the shell, the resulting list of words completely match what was given to the shell. For example '1 2' 3 becomes "1 2" "3"..


Monday, January 02, 2012

Create your own Run Command for any specific Application

You can make your own Run Command (program shortcut) to run a program or a document directly.
To use this feature, you will need to be logged into your computer with administrative rights.

Click Start button and type regedit in Run option then press Enter for next.
Here locate the location to:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App paths 

Now right click on App Paths and select New > Key, title the key and name it whatever you want your run command to be. In this case, we will try to create a run command for googletalk application.

New > Key > googletalk.exe 

Now select the googletalk.exe folder and click right on (Default) string value then click Modify at the right hand side panel.
Here enter the path of the program that you want to execute in the value data field. In our case, the path of googletalk application will be

C:\Program Files\Google\Google Talk\googletalk.exe. 

Now again in right side panel, click right to create a new String value with the name googletalk and its values as C:\Program Files\Google\Google Talk\googletalk.exe.

Now close the registry editor and restart your computer after any changes to go into effect.

How to select last line in a table without CURSOR in DB2

Cursors will be used in DB2 SQL PL stored procedures to perform a complex logic on a row-by-row basis. There are four basic SQL PL statements for working with cursors:
- the DECLARE CURSOR statement to define a cursor
- the OPEN statement to adjust the cursor
- the FETCH statement to retrieve the next row of the cursor
- the CLOSE statement to deactivate the cursor
we can find out last row using cursor with some logic but we can do it without cursor also by using following logic...

db2 "select * from schema_name.table_name order by column_name desc fetch first 1 rows only "

Enjoy The simplicity...

How to Use Sticky Bit on Directory and File

1. Set the sticky bit on Directory
$ chmod 1777 dir

you can assign only sticky bit to an existing directory (without touching any other user, group and other privileges) using chmod command
$ chmod +t dir

dir has rwx permission to everybody, all other users are allowed to do create their files or directories under this directory. However, even when the sub-directories or files under dir is having rwx permission to everybody, only the owner of those can delete or rename those files and directory. Other users cannot delete or rename it because of sticky bit.

Please note that /tmp has sticky bit enabled by default. You might have not noticed that until now. Now you know why /tmp directory is supposed to have sticky bit enabled.

$ ls -ld /tmp
drwxrwxrwt 3 root root 4096 Jan 31 08:29 /tmp

To remove the sticky bit from a directory, do the following.

$ chmod -t dir

Windos Run Commands -- Part 3

To Access…                                                                 RunCommand
Malicious Software Removal Tool 
Microsoft Access (if installed)
Microsoft Chat
Microsoft Excel (if installed)
Microsoft Frontpage (if installed)
Microsoft Movie Maker
Microsoft Paint
Microsoft Powerpoint (if installed)
Microsoft Word (if installed)
Microsoft Syncronization Tool
Minesweeper Game
Mouse Properties
control mouse
Mouse Properties
Nero (if installed)
Control Panel
Network Connections
Network Setup Wizard
Nview Desktop Manager (if installed)
Object Packager
ODBC Data Source Administrator
On Screen Keyboard
Opens AC3 Filter (if installed)
Outlook Express
Password Properties
Performance Monitor
Performance Monitor
Phone and Modem Options 

Sunday, January 01, 2012

Wish you a very very Happy New Year 2012

May this new year bring many opportunities to your way, 
to explore every joy of life & may your resolutions for the days ahead stay firm,turning all your dreams into reality and all your efforts into great achievements. And for fulfilling those achievements you have to dream. 
Happy New Year to you & your loved ones. 
As Dream are not those which comes in your sleep Dreams are those which do not let you sleep.