CSV Writer creates an extra blank row

I’m creating a workflow that creates a .txt to be transfered from a table in my database. I used the node CSV WRITER and changed the extension so it turns into a txt. The workflow is working correctly, but it adds an extra blank row at the end of my input. How can I delete this row from my file before tranfering it?

Hi @pedrocapri ,

It’s more or less common convention in the computer world to end files with a newline, so I’d consider this intended behavior :slight_smile: I’d simply suggest a script to strip it away after writing to the file system?

Here’s an example on my NodePit Space:

Essentially it calls the following script:

var path = Paths.get("/path/to/file.txt");
var content = Files.readString(path);
Files.writeString(path, content.trim());

HTH,
Philipp

5 Likes

Hi @pedrocapri and welcome to the Knime Community.

What @qqilihq said is correct, and he’s also provided a solution to remove that last new line.

However, I’m trying to understand what you are doing. It’s not clear (1) if the source of the file is from a table in your database (it appears so from this comment “transfered from a table in my database”), or (2) if you are trying to write to a csv/txt file, and to eventually read from the file and write to a table in your database (“delete this row from my file before tranfering it”. Transferring it to a table in your database?)

If you are trying to do the (2) one, why don’t you write to the table directly?

1 Like

Hi! The source of my file is a table in my database. Essentially what I’m doing is transforming this table into a txt file and proceed to transfer it to a bucket in S3.
@qqilihq solution seems to work fine if I writ my txt in my local system, however I can’t seem to use it in my workflow since I need to create a temp table to write my file.