Page 1 of 1

help in the below logic

Posted: Mon Jan 02, 2012 10:03 am
by pandeesh
My input sequential file has only one varchar column.
My requirement is,if the record is "abcde",
then it should be loaded as [a][c][d][e].
The length of the record is not fixed.
It may vary. if the input is "123" then the result should be [1][2][3].
One way i can think of is,using the below in filter command:

Code: Select all

sed 's/^\(.\)/[&]/g'
May i know how we can achieve this in Transformer?

Thanks

Posted: Mon Jan 02, 2012 10:28 am
by BI-RMA
Hi pandeesh,

In 8.5 You could use a loop variable in the transformer to do this. But before that I would bet that everything You could do in a transformer will be too much effort to think of anything else than Your mentioned solution.

If the length of Your column was never longer than Varchar(5) You might think of using stage-variables (one per position in the string) and concatenate the results. But I would not prefer that, really.

Posted: Mon Jan 02, 2012 10:31 am
by pandeesh
Unfortunately i am in 7.5 .is there any other feasible solution for this?

Posted: Mon Jan 02, 2012 10:37 am
by soumya5891
Is your maximum length of that particular is fixed?

Posted: Mon Jan 02, 2012 10:40 am
by pandeesh
let us consider 20. So based on the length we need to split and enclose [] in transformer.
That's complex than the filter command method.
However thanks for your inputs.

Posted: Mon Jan 02, 2012 10:50 am
by chulett
This would be trivial in a Server routine.

Posted: Mon Jan 02, 2012 11:23 am
by pandeesh
yes. Here it's:

Image

Thanks

Posted: Mon Jan 02, 2012 1:04 pm
by qt_ky
Take the caret symbol ^ out of your sed command or else it will only act on the first character of each line. You can do it like this also:

Code: Select all

sed 's/./[&]/g' 

Posted: Mon Jan 02, 2012 1:43 pm
by pandeesh
qt_ky wrote:Take the caret symbol ^ out of your sed command or else it will only act on the first character of each line. You can do it like this also:

Code: Select all

sed 's/./[&]/g' 
yes.This is the correct one.