Page 1 of 1

Read a file with a delimiter as string

Posted: Sat Jun 19, 2010 1:28 pm
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

Posted: Sat Jun 19, 2010 2:26 pm
by chulett
Just set the stage property to Delimiter String rather than Delimiter (as in single character) and give that value.

Posted: Sat Jun 19, 2010 4:24 pm
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?

Posted: Sat Jun 19, 2010 5:04 pm
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.

Posted: Wed Jun 23, 2010 11:16 am
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.

Posted: Wed Jun 23, 2010 8:34 pm
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.

Posted: Fri Jun 25, 2010 8:22 am
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 &.

Posted: Fri Jun 25, 2010 9:18 am
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.

Re: Read a file with a delimiter as string

Posted: Fri Jun 25, 2010 9:22 am
by mpuvvati41184
If you are using sequential file use:

final delimiter : none
quote: none
Delimiter : |

I hope this will help you