#147083 - 2005-09-04 10:34 PM
log file pruning / tail
|
iffy
Starting to like KiXtart
Registered: 2005-05-29
Posts: 149
Loc: The Netherlands
|
A little 'challenge'
I'm in need of a routine to prune log files, sorta like you can with the unix TAIL command. That is, I have a few hundred (ascii) log files with 500-50000 lines each (around 10000 on average, average line length 80). I would want to run the pruning daily and only keep the last 5000 lines.
Before actually starting to code I was thing of an efficient way to do this but I'm not coming up with anything imaginative beside the plain read the whole file in memory and replace the file on disk with only the last x lines. If it was a binary file I could do a fileseek/position. Since I don't desperately need exact numbers I was thinking of cheating a little by doing a calculation based on filesize and average line length.
Or I could cheat by calling an external routine like the tail.exe Microsoft provides in their Resource Kit but I prefer 'native code'.
Anyway, I was hoping one of you got an idea for a nice algorithm.
Thanks in advance, Alex
BTW: I don't need a fully coded example, just a pointer in the right direction
|
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 293 anonymous users online.
|
|
|