Issue with variable as column delimiter

Hi,
I am trying to use a variable set to \t and use this variable as column delimiter in a CSV reader node. I use a variable because my column separator may change - depending on other input parameters. . It does not work. 1 get only 1 column with all data. Any idea why it is not working? Is it a bug?

Thanks,
Regards,
Claire

Hi @Claire , the use of a variable in this case might be irrelevant. If you think about it, you will need to update that variable to another separator, so you might as well update it in the CSV Reader node itself, unless you have several CSV Reader nodes and that they all use the same separator, then it would make sense having that variable.

In any case, I’ll still put a demo together for you to use a variable as delimiter. In the future, it’s a good idea to show us what you did so we can point you out what was missing, or if the approach is the correct one or not. And also, there are different ways to implement this, so my way might be different than yours, but it does not necessarily mean that your way is not good, so that is why it’s good to show what you did.

For the demo, I created 2 files with the same data, but one is comma delimited, and the other is tab delimited. I created .txt files, but they will work the same way with .csv or .tsv, or any extension really as long as they’re text files (.csv/.tsv are text files).

The demo looks like this:
image

In the Variable Expressions, I define an expression as "\t" and assign it to the variable delimiter:

In the Flow Variables of the CSV Reader, just set the column_delimiter to the variable that was created, in our case it’s called delimiter:

In the Settings tab, it should tell you that the column_delimiter is controlled by a variable:

I point to the tab_delimited file:

Don’t mind the Preview, the node will not format the data properly until it runs. After running the node:
image

Switching to the comma_delimited one:
First, change the delimiter value to comma:

Then point to the comma_delimited file in the CSV Reader:

Result:
image

Here’s the demo workflow (the text files are also included): CSV Reader delimiter as variable.knwf (8.7 KB)

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.