add single quote in data

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
vsi
Premium Member
Premium Member
Posts: 507
Joined: Wed Mar 15, 2006 1:44 pm

add single quote in data

Post by vsi »

Hi

my requirement data comming like this
column1
abc~cdfg~tx

add single quotes in data where ~ comes like 'abc'~'cdfg'~'tx'
In data may be n number of ~

Any helps, advices would be high appreciate.
Thank you in advance
sunny12345
Participant
Posts: 3
Joined: Fri May 16, 2008 3:14 pm

Post by sunny12345 »

If you know the Maximum occurances of ~ then you can use Field of Function...define as many stage variables as occurances of ~

Field(DSlink.Value,"~",1)
Field(DSlink.Value,"~",2)
Field(DSlink.Value,"~",1)
-----
------
So on

Then Concatinate all these stage variables with '~'
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You can convert each "~" to "'~'" using an Ereplace() function [search the forum] and concatenate a single quote character to each end of the string.

Or, if the source is a file, you could pre-process it with a stream editor such as sed (I note you are on Windows, but assume you have MKS Toolkit or similar available).

If the source is a database table, you can use SQL functions to generate the required delimiters.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
vsi
Premium Member
Premium Member
Posts: 507
Joined: Wed Mar 15, 2006 1:44 pm

Post by vsi »

HI Ray,

thanks for your reply.

in parallel i am not seeing Ereplace function. In parellel any other way to use similar function?
input and out put is a sequential file


thanks
ray.wurlod wrote:You can convert each "~" to "'~'" using an Ereplace() function [search the forum] and concatenate a single quote character to each end of the string.

Or, if the source is a file, you could pre-process it with a stream editor such as sed (I note you are on Windows, but assume you have MKS Toolkit or similar available).

If the source is a database table, you can use SQL functions to generate the required delimiters.
savis
Premium Member
Premium Member
Posts: 27
Joined: Tue Apr 15, 2008 11:06 pm

add single quote in data

Post by savis »

Hi,

If this is the only column available in input or if this is the only column having ~ characters coming in input , use

cat |sed "s/~/'~'/g"

in the filter command(Sequential file)

Input: abc~cdfg~tx

Output:abc'~'cdfg'~'tx

If you want the output data as 'abc'~'cdfg'~'tx', then use a stage variable say quote with value "'" and in transformer use

quote:<Input_col_name>:quote

where quote is the stage variable having value as " ' ".

Note:

[We can also include the option quote=single]
[I even tried the option squote, but if there is single quote within the field then this command adds a \ before each single quote.
i.e) input sdsdsd output : 'sdsdsd'
input sd'sd'sd output : 'sd\'sd\'sd'
]

Gurus,

Please correct me if i am wrong.

Thanks,

Savis
vsi
Premium Member
Premium Member
Posts: 507
Joined: Wed Mar 15, 2006 1:44 pm

Re: add single quote in data

Post by vsi »

Hi Savis,
thanks for your reply,

i given
cat |sed "s/~/'~'/g" at input level and i used "'":input_column:"'"
out put is coming correctly
but
1. when i open the input file first getting blank popup window and then able to view the data
2. job is aborted status and getting this error=> Filter status 65,280

please let me know any suggetions.
thanks
savis wrote:Hi,

If this is the only column available in input or if this is the only column having ~ characters coming in input , use

cat |sed "s/~/'~'/g"

in the filter command(Sequential file)

Input: abc~cdfg~tx

Output:abc'~'cdfg'~'tx

If you want the output data as 'abc'~'cdfg'~'tx', then use a stage variable say quote with value "'" and in transformer use

quote:<Input_col_name>:quote

where quote is the stage variable having value as " ' ".

Note:

[We can also include the option quote=single]
[I even tried the option squote, but if there is single quote within the field then this command adds a \ before each single quote.
i.e) input sdsdsd output : 'sdsdsd'
input sd'sd'sd output : 'sd\'sd\'sd'
]

Gurus,

Please correct me if i am wrong.

Thanks,

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

Post by ray.wurlod »

Search the forum for a parallel version of Ereplace().
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