Answer the question
In order to leave comments, you need to log in
How to read the last line in a text file and then delete it?
There is a large file (250mb) Each line has a link. There is a task that runs on a timer, reads the first / last line, does certain actions with the link, deletes the line from the file, closes the file. How to make it so that it is not resource intensive. Can I have an example?
In principle, it doesn’t matter to me which line is the first or last, the main thing is to quickly deal with the file and close it.
Answer the question
In order to leave comments, you need to log in
I don’t remember how this function works in rubles,
but you can get strings
lines = File.open("file.txt").to_a
lines.first
lines.last
lines.at(5) #пять
last_line = `tail -n 1 file.txt` # last line
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question