Read a file with a delimiter as 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
vsi
Premium Member
Premium Member
Posts: 507
Joined: Wed Mar 15, 2006 1:44 pm

Read a file with a delimiter as string

Post by vsi »

Hi,
I have a file with |& as the delimiter.
eg: abc|&cde|&fgh|&ijk

I need to extract the values based on the delimiter |&

Tried Field () function, but didn't work here.

any other idea?

Thanks
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Just set the stage property to Delimiter String rather than Delimiter (as in single character) and give that value.
-craig

"You can never have too many knives" -- Logan Nine Fingers
vsi
Premium Member
Premium Member
Posts: 507
Joined: Wed Mar 15, 2006 1:44 pm

Post by vsi »

That don't work, as i am reading the file entirely..
and the delimiter count is different for each line.

Here is the file looks like

HEADER|&Value1|&Value2|&Value3
Body|&Val1|&Val2|&|Val3|&Val4
Body|&Val5|&Val6|&|Val7|&Val8
Tail|&Date

I am splitting the file and writing into 3 different files (header, body, tail).

Is there any function in Transformer to extract particular field value?
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

A minor detail you failed to mention in the original post.

I would suggest using the Field() function like you were for a single character, say the pipe as the field delimiter, and then strip the extraneous second character from the field. That or making a pass to convert those pairs to a single character, something that could be as simple as stripping one, then use Field() on the survivor.
-craig

"You can never have too many knives" -- Logan Nine Fingers
raghu22
Premium Member
Premium Member
Posts: 15
Joined: Sun Oct 11, 2009 11:33 am

Post by raghu22 »

That would be a problem,if the source data have | character.

chulett wrote:A minor detail you failed to mention in the original post.
I would suggest using the Field() function like you were for a single character, say the pipe as the field delimiter, and then strip the extraneous second character from the field. That or making a pass to convert those pairs to a single character, something that could be as simple as stripping one, then use Field() on the survivor.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Of course. In that case reverse the choice. That or (as noted) take the extra effort to convert the pair to a single character you "know" won't occur in the source data.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Bongo51
Participant
Posts: 25
Joined: Fri Jun 25, 2010 7:41 am

Post by Bongo51 »

Hi,

Are you or have you imported the table definition for the file as yet?

Please consider that the & sign is not treated as data on input as datastage would see character as a functional character and you cannot use that character as a delimiter value either.
Please attempt first without the &.
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

Change the delimiter in source with something like

Code: Select all

sed 's/\|\&/~/g' yourFileName
and use '~' as your delimiter.

You can do the same within the job.
mpuvvati41184
Participant
Posts: 6
Joined: Fri Jun 11, 2010 7:01 am

Re: Read a file with a delimiter as string

Post by mpuvvati41184 »

If you are using sequential file use:

final delimiter : none
quote: none
Delimiter : |

I hope this will help you
Post Reply