Skip to main content

Hello everyone,

I have a writer, that takes three attributes to write to a text file.

Each time that I run the workspace, the text file output is different than the last time.

I need the output to be in order. I have a header, a body and a footer that should come in that order.

Am I missing something? Do I need to build more attribute types for this to work?

Create a new attribute "sort" with

header = 1, body = 2, footer = 3

Before output sort by "sort".


Hi,

Thank for the suggestion. I tried that already, but it did not work. It only sorts the output of each attribute individually, and not the final output. When I connect the sorter to the text writer, I will have to select each attribute individually.

imageimage 

What I have end up doing is change the order of the individual attributes and its seems to be working. But I am sure there is a better wat.


No.

You make a new attribute: Name: sort Value: 1, 2 or 3

if feature = header then sort is 1.

if feature = body then sort is 2.

if feature = footer then sort is 3.

Sorter sort by sort.

 


@navid.fotovaty, perhaps you can share (a screenshot of) your workspace along with the (sample) data you are using. If I can reproduce it, I can assist you more effectively.

 

Right now, it's not clear to me whether you have only one header, body, and footer row, or multiple ones. Are we talking about the sequence of header, body, and footer in a textfile (example 1)? Or a series of header, body, and footer attributes (example 2)?

 

Expected vs Result (example 1)

pheader] ]body] ]footer] vs sbody] ]header] ]footer]

 

Expected vs Result (example 2)

3] >body 3] >footer 3]

2] >body 2] >footer 2]


Hi Ernie,

This is my current workspace, and its working, but I am sure there is a better way to sort this as tom suggested.

imageUnfortunately, I only have access to live data and cant share a sample.

This is what my sort doing now, although I don't think it make much a difference what it does,

image.pngimageimageI believe what fixed the problem was adding the concatenator after the sort, which created one single output for the text writer.


Hi Ernie,

This is my current workspace, and its working, but I am sure there is a better way to sort this as tom suggested.

imageUnfortunately, I only have access to live data and cant share a sample.

This is what my sort doing now, although I don't think it make much a difference what it does,

image.pngimageimageI believe what fixed the problem was adding the concatenator after the sort, which created one single output for the text writer.

Great you’ve found a solution.

 

I would suggest to replace the sorter and stringConcatenator with just one AttributeCreator.

 

Within the attribute creator you’ll be able to create the attribute ‘text_line_data’. You can add the attributes as a value (e.g. @Value(1) @Value(2) @Value(3)). This prevents the assignment of a new attribute value in the writer and makes your workspace less complex.

 

Finally, I would recommend to use description attribute names. Just use attribute names as ‘header’ and ‘body’ if they explain the corresponding values. It makes a big difference when your colleagues needs to maintain this workspace :-)


Hi Ernie,

I had tried that already, but it does not sort them correctly, please see below.

imageimageIt put the body above the header and footer.

Am I doing anything wrong there?

The reason I was using 1,2 and 3 was that it was the only way the sort would work for me.


Are you looking to arrange all rows in a specific order instead of columns? If so, one approach could be to add a counter transformer. Afterwards, you can sort all features using the sorter transformer based on the "_count" value as a reference.


Hi Ernie,

I am not sure what you mean. I attached a text file, which is the final result, that the text write should produce.

In the text file, the Header should be at the top, followed by the body and end with the footer. The header and footer will always be one line, where as the body can be multiple lines up to couple of hundreds.

 


Reply