cancel
Showing results for 
Search instead for 
Did you mean: 

OS command for sorting in file adapter

Former Member
0 Kudos
97

Hi All

I have a requirement wherein I have to sort a CSV based on a couple of columns. I believe this can be achieved by OS commandline argument. What exactly would be the code for the same that needs to be fed in the source file adapter?

And can we use perl script here?

Regards

Soumen Das

Accepted Solutions (0)

Answers (1)

Answers (1)

rodrigoalejandro_pertierr
Active Contributor
0 Kudos

why dont you sort the file in the Mapping defining a DT according to result structure?

Former Member
0 Kudos

OK lemme be a bit clearer...Following is my structure...Source and target same...

Node(0...n)
----Field1
----Field2
----Field3
----Field4
----Field5

Now I need to sort based on Field2 and Field4 lets say. Target should have the rows re-arranged according to the sort result. How do we do it using Graphical mapping?

former_member181962
Active Contributor
0 Kudos

Hi Soumen,

You can do it this way.

Concatenate Field2 and Field 4. Pass that as an input to SortByKey (second input). Pass the field that you want to sort to the first input of the SortByKey function.

Best Regards,

Ravikanth Talagana

baskar_gopalakrishnan2
Active Contributor
0 Kudos

There are few ways to achieve this. If your Field2 is the field decides then

First sort field2 .. since it value can occur in the multiple context.. bcuz o to many
step 1

field2 --> remove context --> sort --> split by value (context change) ---> field2

step 2
sort field1 based on field2
field2 --> remove context  ---> 1      
field1--->remove context  --->  2

inputs 1 and 2  ---> sortbykey --> SplitByValue(each value) -->field1

Like that we can do for other fields like field3, field4 etc repeating second step for every field

Former Member
0 Kudos

@Bhaskar : You logic holds true if the mentioned field 2 is different in every context. But my requirement is if Field2 is similar in two contexts Field1 values need to be sorted which aint happening if I apply this. Any idea how to achieve this?

@Ravi : Concatenation wont work because the fields aren't fixed length.

Former Member
0 Kudos

@Bhaskar : You logic holds true if the mentioned field 2 is different in every context. But my requirement is if Field2 is similar in two contexts Field1 values need to be sorted which aint happening if I apply this. Any idea how to achieve this?

@Ravi : Concatenation wont work because the fields aren't fixed length.

former_member181962
Active Contributor
0 Kudos

HI Soumen,

Are these fields numbers? If yes, then you can try

concat(Field2->formatNum(00000000000),Field4->FormatNum(00000000000)) and provide this as input to sortbykey function.

Best Regards,

Ravi