Reading and Writing into a text file from the function node

Sorry, I should have made it more clear. I have a query that writes in to a file (say file A) using the file in node(using the /n). The first query returns around 20-30 messages. So in file A I have the 20 messages plus an extra 21st line that's empty. I have another function that takes one line at a time from file A and pumps it into the query and returns some more information for me. So After the last line from file A is read, the empty 21st line is also read from the file. which I am trying to avoid.

I am afraid you still have not answered the question. I presume you mean a File Out node, but the question is when you write to the file are you writing the complete file with one message or sending the file out node multiple messages, one for each line in the file?

Sorry I messed up the last message, I have editted it.

Sorry again. using the file out node I write one line at a time, not the entire content of the file.

In that case put a debug node monitoring the data going to the file. Possibly you are sending an extra empty message, so the file includes a blank line on the end, or possibly the last line you send already has a newline on the end so it ends up as two lines when the node adds the extra one.
[Edit] I presume you have looked at the file with a text editor or similar to confirm that there really is a blank line on the end, and that it is not your flow when you read it in again that is adding the extra query.

@Colin it was because the last message is always adding a new line to the file. I solved it by using a split node and sending the line to the query only if it is not empty.

The last message will not add a new line to the file unless there is something different about it. It does not add a new line for previous messages so how does the file out node know that the last one is the last one unless it is different to previous ones?

@Colin when I said "it was because the last message is always adding a new line to the file" that was the database values from SQL. wasn't a problem with the file node. It was just easier for me to use a split node.

PS: I should probably work on my communication, sorry I confused you a few times.

Hi @Colin @dceejay @zenofmud @TotallyInformation @ukmoose, I am almost at the end of the project right now. Thank you again for helping me figure this out. One last question; In case I needed to restrict the file-out node to send just one message (just first line) to a function node and stop sending anymore lines, is there a node I can use in between the file-out and the function node that will help me achieve that?

thank you.

How will whatever you put downstream to pass on only the first line know whether subsequent lines are the remainder of the file or the start of the file for the next time you read it?

It will be overwritten the next time the file is read. I just need the first line.

I think you don't understand my point. If you configure the file node to send a message for each line then the downstream logic must pass on the first message then ignore the following messages. But for how long must it continue to ignore messages? It would have to have some way of when to expect a new 'first' line again.
I think the easiest way will be to configure the file node to read the complete file and pass it on as one string. Then you can have a function node that just passes on the first line and throws the rest away.
Another alternative would be to use an Exec node to execute a command that just reads the first line of a file. The command

head -1 filename

would do that. That assumes you are running in a Linux environment of course.

any other ideas? I tried the suggestion Colin gave me, will work on it tomorrow.

Do you mean it did not work?

Thank Colin, I had to work with windows environment but I used the same idea, it worked.