replacing a string

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

rickrambo
Participant
Posts: 21
Joined: Wed Jul 27, 2005 11:27 am

replacing a string

Post by rickrambo »

Hi,
I have an input string 'fantacy', I would like to covert this string to 'faxyzcy' in the TRANSFORMER Stage. That is 'nta' in the input string should be replaced by 'xyz' in the output. Only the occurrance of 'nta' need to be replaced but not the individual chars...so CONVERT function won't work.
What function I will use to achieve this.

Using 7.5.1 (PX) on UNIX.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Give us your thoughts.

In a server job you would have looked at Ereplace() but this is not available in parallel jobs. Clearly an approach that uses substrings and concatenation, plus If..Then..Else, seems to be indicated.

Can you guarantee that the string-to-be-replaced occurs not more than once in the field? If not, you're probably up for a different approach - perhaps an External Filter stage using (perhaps) awk.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

Or Index() in transformer to find the and replace with the given string. If not sure about the number of occurance, you can make use of Dcount().
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
rickrambo
Participant
Posts: 21
Joined: Wed Jul 27, 2005 11:27 am

Post by rickrambo »

anybody has thoughts on this. Little more info, the part of the string I am trying to replace 'nta' can appear any where in the input string 'fantacy'.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Awaiting YOUR answer to my question that will guide my answer.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
c_cri
Participant
Posts: 8
Joined: Mon May 10, 2004 1:04 am

Re: replacing a string

Post by c_cri »

Hi, try the Ereplace function in the transformer:

Example

Ereplace('abcd.doc','.doc','.txt') returns abcd.txt

Hope this helps

Chris
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Ereplace() is not available in the parallel Transformer stage.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
samsuf2002
Premium Member
Premium Member
Posts: 397
Joined: Wed Apr 12, 2006 2:28 pm
Location: Tennesse

Post by samsuf2002 »

i am not sure what is the job scenario but u can develop a small server job and use Ereplace() out put to a file and use that file as input to ur parallel job..............
hi sam here
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

Not a job for each transformation. :wink:
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

StageVar "AntLoc" set to "INDEX(In.Column,'nta',1)"
StageVar "NewString" set to "IF AntLoc=0 THEN In.Column ELSE In.Column[1,AntLoc-1]:'xyz':In.Column[AntLoc+2,9999]"

this will replace the first instance of "ant" with "xyz" in the string in a PX job.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Still awaiting an answer to "Can you guarantee that the string-to-be-replaced occurs not more than once in the field?". Arnd's answer is sufficient if the answer is "yes", but not if the answer is "no".
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
clshore
Charter Member
Charter Member
Posts: 115
Joined: Tue Oct 21, 2003 11:45 am

Post by clshore »

Since it's EE, why not a function or buildop based on C regcmp and regex?
Build it generically enough for re-use, and voila, you have a new arrow in your quiver.

Carter
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Good point, but original question required "in Transformer stage".
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
clshore
Charter Member
Charter Member
Posts: 115
Joined: Tue Oct 21, 2003 11:45 am

Post by clshore »

True for the buildop, but don't Custom Functions become available to choose via the expression editor menus in Parallel Transformer?
ISTR adding one (it's been a year or so back).

Carter
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Good point - though a parallel Routine is not a BuildOp (which is a stage).
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply