Reading/Deleting Last Line Of File
warrenkuhl at gmail.com
Tue Feb 9 08:48:59 CST 2010
I will give this a try. I was trying to go down the same path by
getting the number of records of the file...then trying to determine
if I could just read the last line and removing the EOF. Is there
anyway to specifiy a READ to a certain line of a file without reading
through the whole file?
On Tue, Feb 9, 2010 at 8:34 AM, Jim Bufalini <jim at visitrieve.com> wrote:
>> I have a large text file (100,000,000+ records). I need to write a
>> utility that removes the last record of the file. Is there anyway to
>> just remove the last record without reading through the complete file
>> with RunRev?
> This is totally untested but "logically" you could:
> 1. First get the size of the file on disk and approximate a character offset
> that should be only a few lines from the end of the file.
> 2. Then Open the file for read and read from file starting at the char
> offset you calculated to EOF into a var and delete the last line of the var.
> 3. Then Close the file and Open it again for write.
> 4. Now write the var to file at the same starting offset you read from.
> The reason you don't use open for update is that you want to open the file
> for write, so that whatever you write to the file replaces everything from
> the offset to the EOF. Update will replace chars and leave the last record
> at the end.
> What I don't know here is if internally the read/write from file at start
> still has to go through the entire file to calculate the starting offset, so
> I don't know how long this will take on a file of your size. But, at least,
> doing it this way won't require reading the whole file into memory and
> should result in the last line being deleted from the file in the quickest
> way available.
> Aloha from Hawaii,
> Jim Bufalini
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
More information about the use-livecode