Extract date part from file name

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
srekant
Premium Member
Premium Member
Posts: 85
Joined: Wed Jan 19, 2005 6:52 am
Location: Detroit

Extract date part from file name

Post by srekant »



Hai

I have a scenario where i have to strip of date part from the file name

Ex:
Input
method_yyyymmdd.csv

Output
yyymmdd

and want to use it as a default value for one of the column in my target.


Any ideas how to achieve this.
Sree
ashwin2912
Participant
Posts: 57
Joined: Wed Jan 26, 2005 10:22 pm
Location: India

Post by ashwin2912 »

Use this in a transformer:
Input [8,8]

Or in Modify stage:
substring(8,8)


Now, How will you get the filename into a transformer/modify?
That would depend how are you reading this file...if you are using job parameters you can use it with ease.
Ashwin
srekant
Premium Member
Premium Member
Posts: 85
Joined: Wed Jan 19, 2005 6:52 am
Location: Detroit

Post by srekant »

we are using parameters can u guide on how to get this into a transformer.
using cut command in unix i am able to seperate the date part from file name and direct it to another file.
Sree
dsxdev
Participant
Posts: 92
Joined: Mon Sep 20, 2004 8:37 am

Post by dsxdev »

hi Srekant,
if you are using Job parameters then you need to pass the date part in the file name as Job parameter.

now it depends on how you are invoking your job if it is through a unix script

then use cut command to get date, which you have already done it.
When you invoke your job using dsjob utility pass this date value as a job parameter value as

JobParam=dd-mm-yyyy , i.e as name=value pair.

This job parameter can be used in your transformer.
In transformer column derivations on right click you can choose Job Parameters and from the list pick the job parameter.

Thus you can access the parameter value.

Other wise may have to use job Control or sequencer to pass the date value to the job as a parameter.
Happy DataStaging
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

Hi,
You can directly use the parameter in transformer and use Index() funciton to split the date alone. ("_" can be used to isolate the date)

regards
kumar
roy
Participant
Posts: 2598
Joined: Wed Jul 30, 2003 2:05 am
Location: Israel

Post by roy »

Hi,
What DS version your on?
If 7.5 or better yuo can use a sequence job to run a command returning the file name and use User Variable stage to define a variable holding the date by using basic routines and pass this variable as a parameter to your job.

If your using automaticly handle activities that fail you'll probably need to use a server job to return this info via user status and use that as the parameter value.

IHTH,
Roy R.
Time is money but when you don't have money time is all you can afford.

Search before posting:)

Join the DataStagers team effort at:
http://www.worldcommunitygrid.org
Image
Post Reply