Quick question, Is it possible to open a log file and read it from below?

I know you can do this;

fopen('/var/log/messages','r')

But this read the file from the top. This takes quite some time when the file is too big in size.

Would it be possible to read the file from bottom to top?

Thank you

Wesley

1 Answers

0
Deepak Bhavale On

You can implement the following Pseudocode for the solution of your problem:

fopen('/var/log/messages','r')

while (fgets () != NULL)
{
   push line to stack
}
open output file
while (stack no empty)
{
   pop stack
   write popped line to file
}