Which would be the best way to read a file from the end?
The first solution that goes to mi head is get buffers of i.e. 10 lines starting by the end; so get 10 last lines to read from line -10 (until line -1), else get from -20 until -10, and so on.
Which would be the best way to read a file from the end?
The first solution that goes to mi head is get buffers of i.e. 10 lines starting by the end; so get 10 last lines to read from line -10 (until line -1), else get from -20 until -10, and so on.
http://golang.org/pkg/os/#File.Seek
It's also recommend that you check out the source of tail to understand how to correctly implement this functionality.
I know this thread is old but I found it trying to find a solution to the "read from end of file" problem. AKA i wanted a way to "tail" in go. Well using Stephen's basic idea (7/30/12), I built a "tailing" function in go. Figured I would post this here in case some else comes upon this thread randomly trying to solve this same problem.