How to Read only the last line of a text file in Lua? -


I have a program that generates text files that can be up to 20 mts in size. Sometimes I only care about the last line in the file, is there a way to read that file along with this file to remember the rest of the files?

I can be mistaken but without some tactics, it seems that you can not If you have any estimation of the length of the lines, you can open a file and then from the end, say 1Kb.

  local f = io.open ([[C: \ test_file.txt]], "r" local len = f: seek ("end") f: seek ("set", Len - 1024) local text = f: read ("* a") print (String.match (text, "[^% c] * $") f: close ()  

Hope this helps, note that the pattern needs some refinement. It currently believes that no control letter is visible on one line if you have IE tabs in the line, then by the end of the file From there it will capture.


Comments