Skip to main content

Posts

How to remove the last newline character in a unix file

How to remove the last newline character in a unix file truncate -s -1 <file> eg. shop&save
Recent posts

How to DUMP dataset to a flat file in Datastage ?

This can actually be found on ibm website : http://www-01.ibm.com/support/docview.wss?uid=swg21625028 $ cd /app/ibm/InformationServer/Server/DSEngine/ $ . ./dsenv $ export APT_CONFIG_FILE=/app/ibm/InformationServer/Server/Configurations/default.apt $ $APT_ORCHHOME/bin/orchadmin dump -delim '|' sample_dataset.ds > sample_dataset.txt In the above example the DSEngine location my vary depending on your installation path.

How to extract prefix or suffix on a unix string

Sometime you are processing a lot files and you have to construct a dynamic prefix and suffix based file names. So you can search for multiple files based on prefix pattern and suffix pattern. Here's how you extract the PREFIX of a string given you have some sort of delimiter in the string itself. bash-4.1$ echo "THISPREFIX_blahblah_yyymmdd.txt" THISPREFIX_blahblah_yyymmdd.txt bash-4.1$ var123="THISPREFIX_blahblah_yyymmdd.txt"; file_prefix=" ${var123%%_*} " ; echo $file_prefix THISPREFIX bash-4.1$ In the above example string what we want to extract are the charcters after the _ (underscore) thus in our variable manipulation we specified _ after the %% which denotes that we get all the characters before _. So for the SUFFIX extraction the patter is similar only we use ## instead of %%. see below : bash-4.1$ echo "THISPREFIX_blahblah_yyymmdd.txt" THISPREFIX_blahblah_yyymmdd.txt bash-4.1$ var123="THISPREFIX_bla

how to create dynamic variable in unix ?

This is a problem where in you a have a config file and you have wrapper script and a child script where in your wrapper and child script are generic enough to process certain task depending on the parameter you pass to create your dynamic variable and source your static value from a config file, this way you wouldn't need to touch your scripts but only the config. I found a lot of ways through googling easiest would be the bash solution but fortunately i am using ksh so another one was the use of eval, however most of the solutions i found using eval on the net didn't work for me, either i didn't know how to use or apply it, so i tried a few combinations and below is what worked for me : If your doing it in bash shell its quite easy : dev_config_var=abc;  dynamic_value=dev;  dynamic_var=${dynamic_value}_config_var;   echo ${!dynamic_var} so you see the trick if you are in bash is just "!". but if we are doing in ksh, then its a different story.

How to override parameter set value for a specific parameter in Datastage via unix command line ?

Sometimes you are running a data fix for production in datastage eg. back loading data and you get lazy to create a monstrous SQL just to replicate what the actual job is doing. You find yourself creating a unix script replicating the sequence call to the jobs that only populates the table you are fixing, of course you do not want other jobs in the sequence to be re-run during the fix which will mess up other tables. An then you come across a parameter set in which you only need specific values of the parameter set to be passed with different values eg. Connection details. Now that's simple if your parameter set is not importing environment variables. As per IBM it should just be : dsjob -run -wait -jobstatus -param " paramset.paramfield"="myvalues" MYDSPROJECT my_sample_ds_job see the following link : https://www-01.ibm.com/support/knowledgecenter/SSZJPZ_11.3.0/com.ibm.swg.im.iis.ds.direct.doc/topics/t_ddesref_running_job_command_line.html Its a di

Where can you find .odbc.ini and tnsnames.ora in Datastage server ?

Open up the director log for any Datastage job, you'll notice that after the logs that says  "Starting job..." "Attached Message Handlers: " "Environment variable settings: " Open Up that Environment variable settings logs and you will find a bunch of ENV variables being set at the start for execution. Just copy and paste that in any text editor and search for the ODBCINI for the .odbc.ini and TNS_ADMIN for the tnsnames.ora. You should see the following in the env variable settings logs, it maybe different but it will look the same : ODBCINI=/app/ibm/InformationServer/Server/DSEngine/.odbc.ini /app/ibm/dba/oracle_<version>/product/<version>/client_1/network/admin eg.  TNS_ADMIN=/app/ibm/dba/oracle_11_2/product/11.2.0/client_1/network/admin

How to pass the output of your execute immediate select list in oracle pl/sql to variables ?

This i how i did the dynamic query and pass the output of a select statement from an execute immediate into variables SET ECHO OFF SET SERVEROUTPUT ON SIZE 1000000  SET FEEDBACK ON SET TIMING ON DECLARE  mysql_statement clob; var_record_count number; var_field1 number; var_field2 varchar2(30 CHAR); Begin for my_list in (  select 1 as record_count, 101 as field1, 'record number 1' as field2 from dual union select 2 as record_count, 102 as field1, 'record number 2' as field2 from dual union select 3 as record_count, 103 as field1, 'record number 3' as field2 from dual ) LOOP /*-- build your dynmic sql and assign to a variable --*/ mysql_statement := 'select '||my_list.record_count||', '||my_list.field1||', '''||my_list.field2||''' from dual'; /*-- display your dynamic sql--*/ DBMS_OUTPUT.PUT_LINE(mysql_statement); /*-- execute whatever you sql is using execute immediate and pass the result for