Friday, February 17, 2012

Regular Expressions

Regular Expressions
. (dot) Any single character except newline
* zero or more occurances of any character
[...]        Any single character specified in the set
[^...]        Any single character not specified in the set
^ Anchor - beginning of the line
$ Anchor - end of line
\< Anchor - begining of word
\> Anchor - end of word
\(...\)  Grouping - usually used to group conditions
\n Contents of nth grouping

[...]         Set Examples
[A-Z] The SET from Capital A to Capital Z
[a-z]   The SET from lowercase a to lowercase z
[0-9]         The SET from 0 to 9 (All numerals)
[./=+] The SET containing . (dot), / (slash), =, and +
[-A-F] The SET from Capital A to Capital F and the dash (dashes must be specified first)
[0-9 A-Z] The SET containing all capital letters and digits and a space
[A-Z][a-zA-Z] In the first position, the SET from Capital A to Capital Z

Regular Expression Examples
/Hello/ Matches if the line contains the value Hello
/^TEST$/   Matches if the line contains TEST by itself
/^[a-zA-Z]/ Matches if the line starts with any letter
^.*SET.*$  Select whole line which start with "SET"
/^[a-z].*/    Matches if the first character of the line is a-z and there is at least one more of any character 
"^.* as " select a phase from beginning up to as word. Can be used to replace "xxxx as c_q6" as "c_q6"

following it
/2134$/ Matches if line ends with 2134
/\(21|35\)/   Matches is the line contains 21 or 35
/[0-9]*/         Matches if there are zero or more numbers in the line
/^[^#]/        Matches if the first character is not a # in the line
\r\n[^\r\nO]  Matches the lines start with \r\n in previous line but not start with O

1. Regular expressions are case sensitive
2. Regular expressions are to be used where pattern is specified

Tuesday, February 14, 2012

Bash command with parameters to run PDI transformation file
echo "Enter the name of the sample file(eg CVAR_Good_20110104):"
read sample_file #sample_file is the variable which pick the entered value
echo "Enter the wave (eg 1):" read wave_no   #wave_no is the variable 
/home/kettle4/ -file=/home/pdi_transforms/ibmcvar/fatigue/pdi_transforms/fatigue_export.ktr -norep -param:FILENAME=$sample_file -param:WAVE=$wave_no -XX:-UseGCOverheadLimit
PDI Transformation properties (Ctrl + T)
Define the parameters name in transformation properties and keep the default values empty

windows batch file with few validations
ECHO  Enter your job number %1
SET /P userin=

IF "%userin%"=="" (
 ECHO ----------------------------------
 echo "You should enter a job number..."
 ECHO ----------------------------------
IF NOT EXIST Q:\secure\%userin% (
 ECHO %userin% Job directory doesn't exist in Q:\secure\
 ECHO -----------------------------
 ECHO Please enter valid job number
 ECHO -----------------------------
IF EXIST Q:\secure\%userin% (
 ECHO ------------------------------------------------- 
 ECHO Maximum sample numbers are being calculated......
 ECHO This may take few minutes. please wait...........
 L:\kettle4.2\Kitchen.bat /file="W:\Panelsample_iss\max_sample_no\max_sample_no.kjb" "-param:jobno=%userin%" > nul
 ECHO -------------------------------------------------  
 ECHO -------------------------------------------------
 ECHO Please check max_sample_nos_%userin% file inside 
 IF EXIST w:\%userin%\Sample\ToLoad (
  echo w:\%userin%\Sample\ToLoad
 ) else ( 
  echo w:\%userin%US\Sample\ToLoad directory