ok, here's some ideas and a few code snippets for a nice algorithm (not sure if there is already one in the UDF library, might want to check) ... but basically create an array of lines (buffer) the same size as the number of tail lines you want to keep, and as you read the file, store these lines in your buffer. When done reading, go back and write out your saved lines.

Create a $variable that will hold your "numbers of lines to keep", kinda like this:

$KEEP = 5

Create an array dimensioned that size, like this:

Dim $Array[$KEEP]

and create another variable that will be your indexer into this array, as you read the lines in the file:

$Index = 0

Create a variable called "Rollover" that will indicate if you extend pass the end of this array when reading the file:

$RollOver = 0

Open your file and start reading the lines into your buffer:

Code:

$array[$index] = readline(1)

while @ERROR = 0
$index = $index + 1
if $index > $KEEP
$RollOver = 1
$index = 0
endif
$array[$index] = readline(1)
loop



Note that if you blow past the buffer size ($index > $KEEP) you wrap around to the beginning of the buffer, BUT - you set the RollOver flag so that later you will know this.

After your done reading the file, close it, then pump out what you got - you would have to take into consideration whether you rolled-over or not. Maybe something like:

Code:

if $RollOver = 0
for $i = 0 to $index - 1
? $array[$i]
next
else
for $i = $index + 1 to $keep
? $array[$i]
next
for $i = 0 to $index - 1
? $array[$i]
next
endif