Removing a specific character from 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

Post Reply
devsonali
Premium Member
Premium Member
Posts: 155
Joined: Sun Mar 18, 2007 2:31 pm

Removing a specific character from string

Post by devsonali »

Hello everybody
I have a string coming in
its like abc def hsk nmps etc

My requirement is to remove any letter 'a' from the words within the string if it appears as the last letter

For example
"abc def abca" should be come "abc def abc"
"abc def' will not change
"abc nko 2090a sksa" becomes "abc nko 2090 sks"
so on and so forth

As you noticed the string can be of varying length including words

I am trying by looping the string ( unsuccessfully ) and wanted to see
if anybody has better,easier way to handle this

Thank you for looking
devsonali
Premium Member
Premium Member
Posts: 155
Joined: Sun Mar 18, 2007 2:31 pm

Post by devsonali »

Update - Somebody suggested (not finding the post anymore ) using a trim function with 'T'
This helps because I can combine it with other logic to perhaps work it out
However , Trim( string,"a","T")
Trim with T option only seems to work for last words(in this case)
so
"abc def abca" becomes "abc def abc" (as expected)
but
"abc nko 2090a sksa" becomes "abc nko 2090a sks"

Thank you for suggestion

Still looking for options to handle that
rkashyap
Premium Member
Premium Member
Posts: 532
Joined: Fri Dec 02, 2011 12:02 pm
Location: Richmond VA

Post by rkashyap »

Try External Filter Stage with

Code: Select all

Filter sed
Arguements  's/a / /g;s/a$//g'
devsonali
Premium Member
Premium Member
Posts: 155
Joined: Sun Mar 18, 2007 2:31 pm

Post by devsonali »

Thank you Kashyap, will try to implement that
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

What is your source? The previous suggestion assumes a file, I do believe.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You could create a loop in a Transformer stage that loops through the words. Treat the field as a space-delimited string, use Field() function to extract the individual words.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
rkashyap
Premium Member
Premium Member
Posts: 532
Joined: Fri Dec 02, 2011 12:02 pm
Location: Richmond VA

Post by rkashyap »

Loop in a Transformer would probably perform faster than Unix command running in External Filter stage. I believe that External Filter may be able to process data from any source.
devsonali
Premium Member
Premium Member
Posts: 155
Joined: Sun Mar 18, 2007 2:31 pm

Post by devsonali »

Thank you for all your inputs , I have tested (more testing in progess ) it by applying space (trailing) and looking for 'a ' and replacing it with ' ' . I will also test using loops and external filter as suggested

Although , for looping , my logic greatly depends on the sequence of stage variables i am using for other transformation - so wanted to know , does a loop variable execute after the stage variables do ?
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

For each row processed all stage variables are evaluated before the loop is executed.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

A recent discussion on execution order, including a link to where it is officially documented! :shock:

:wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply