Read a csv file from a specific line

I have in a txt file stored the line number that I previously read from a csv file.
Since this csv file can be updated by adding 1 or more lines, how can I read this csv starting from the following line from the last line read up to the last line in the csv file?
Thank you

If you are on Linux: You can use an exec node to call tail +n /full/path/to/file where n is 1 more than the last line read.
It will read the rest of the file into a single string, so it probably needs a split node too.

There is a node node-red-node-tail.
I think it's like the Linux tail -f command ( -f = follow. Gets any new lines written to the file).
Maybe you can use this?

If you are stuck and can cope with some javascript, you could probably use the following in a function node:

csv-parser - npm (npmjs.com)

If the csv file is not so big that reading it whole would effect performance to much you might just read the whole file every time.

But only forward the message if a certain count limit is reached.

So the counter will be set using your row number to a maxlimit. When it reaches the limit it will open a get lettong the rest of the messages go in to your flow.

For this to work the file in node should be configured to 'send msg.payload per line'

Using node-red-contrib-counter and node-red-contrib-simple-gate

If it is small enough, I agree, read the whole file, use the CSV node to convert to JSON and split the resulting array from the required number (which you read in using a separate file node) either using a function node or JSONata.

If you are making the csv file with node-red as well... it might be better to store your data in a database. There are some sql nodes.

It will give much more features to select the data you want get in to your flows.

1 Like

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