Reading file line by line

#1

Good Day

I'm reading a file and it reads everything all once using the file reader node, is it possible to read a file line by line every second. For instance:

Read-
send as payload-
wait second-
...
Read next line-
send as payloas-
wait a second....

Many Thanks

#2

It might be helpful If you tell us more about what you are trying to do with the lines of text.

#3

You can use the File node to read the entire contents in one go and configure it to send one message per line. Then use a Delay node configured in 'rate limit' mode to 1 message per second.

#4

I have a large data file with around 50 000 entries, and I want to read each entry every second as a payload and convert the string into integers, then send these integers to another device, currently my setup is as described by @knolleary.

#5

That is my current setup, I'm asking if is it possible t read each line every second because the file im reading changes aswell, from what I'm understanding, when the file updates, and the reader node reads, it reads everything all over again plus the new line.

#6

It's going to take almost 14 hours to do what you are doing, how often does the file change? If you are using Linux you can use the "tail" node to monitor the file in real time for changes.

#7

Exactly! lol, The solar panel system updates the data every second, so 'd like to read the new entry every second as well. Then after monitoring the file change? Re-read the whole file again?

#8

Like I said, if you are using Linux try the Tail node. Or have I missed something?

1 Like
#9

okay thanks let me attempt:+1:

#10

Do you have any control over that system? It would be better for access in node-red if you could get it to do something like feeding each new value into MQTT.

Otherwise, as @ghayne suggested, use the tail node which will give you each new line as it comes in.

1 Like
#11

Thanks @ghayne, It does what I need it to .

Thanks!