Re: Reading/Deleting Last Line Of File

2010-02-12 Thread Alex Tweedly
Jeff Massung wrote: I'm still new to Rev, but in other languages this is dead simple: ... // nuke everything else at the end of the file trunctate(fp, new_len); ... Done. Now, maybe this isn't as easy in Rev as it is in C and *many* other languages. But it should be [if it

Re: Reading/Deleting Last Line Of File

2010-02-12 Thread Alex Tweedly
Richard Gaskin wrote: That looks similar to what I posted here on the 9th: open file tFile for update seek relative -1000 in file tFile repeat read from file tFile until cr if it is not empty then put it after tBuffer else delete last line of tBuffer

Re: Reading/Deleting Last Line Of File

2010-02-12 Thread Alex Tweedly
Jim Bufalini wrote: Just one thing Alex, you need to: put URLDecode(the detailed files) into t in case the file name has, for example, a space in it. Thanks Jum, I didn't spot that. But then, if the file name had a comma in it, I'd be caught out. I think what I needed was to

Re: Reading/Deleting Last Line Of File

2010-02-12 Thread Richard Gaskin
Alex Tweedly wrote: Richard Gaskin wrote: That looks similar to what I posted here on the 9th: open file tFile for update seek relative -1000 in file tFile repeat read from file tFile until cr if it is not empty then put it after tBuffer else

RE: Reading/Deleting Last Line Of File

2010-02-12 Thread Jim Bufalini
Richard Gaskin wrote: But FWIW, I tried your version and it seemed to leave the file unchanged If your original file ends in a cr then Alex's code would end in absolutely no change. ;-) Aloha from Hawaii, Jim Bufalini ___ use-revolution mailing

Re: Reading/Deleting Last Line Of File

2010-02-12 Thread Richard Gaskin
Jim Bufalini wrote: Richard Gaskin wrote: But FWIW, I tried your version and it seemed to leave the file unchanged If your original file ends in a cr then Alex's code would end in absolutely no change. ;-) Thanks, Jim. I tried it both ways; no change to the file's contents, although the

Re: Reading/Deleting Last Line Of File

2010-02-12 Thread Alex Tweedly
Jim Bufalini wrote: Richard Gaskin wrote: But FWIW, I tried your version and it seemed to leave the file unchanged If your original file ends in a cr then Alex's code would end in absolutely no change. ;-) That's not what my testing showed (or appeared to show). Here's the short

Re: Reading/Deleting Last Line Of File

2010-02-12 Thread Alex Tweedly
Richard Gaskin wrote: Jim Bufalini wrote: Richard Gaskin wrote: But FWIW, I tried your version and it seemed to leave the file unchanged If your original file ends in a cr then Alex's code would end in absolutely no change. ;-) Thanks, Jim. I tried it both ways; no change to the

RE: Reading/Deleting Last Line Of File

2010-02-12 Thread Jim Bufalini
Alex Tweedly wrote: I suspect the *trick* of opening a file for append, then seeking back into the middle of the file before doing a write is OS-dependent. It's certainly not documented (either way), and I was surprised when Jim said that it could be done. Intuitively, 'append' should mean

Re: Reading/Deleting Last Line Of File

2010-02-12 Thread J. Landman Gay
Alex Tweedly wrote: I strongly suspect it only works on Windows :-( Sorry. I don't have either a Mac or Linux box to try it on, however I did just try it on the on-rev server (as an .irev script) and it also appears to leave the file unchanged there. I wonder if it has to do with the

Re: Reading/Deleting Last Line Of File

2010-02-12 Thread J. Landman Gay
J. Landman Gay wrote: Alex Tweedly wrote: I strongly suspect it only works on Windows :-( Sorry. I don't have either a Mac or Linux box to try it on, however I did just try it on the on-rev server (as an .irev script) and it also appears to leave the file unchanged there. I wonder if it

Re: Reading/Deleting Last Line Of File

2010-02-12 Thread Kay C Lan
On Sat, Feb 13, 2010 at 8:25 AM, Alex Tweedly a...@tweedly.net wrote: Could you try this in your multi-line msg box and let me know what it does on Mac ? put abcdefg CR into URL file:b.txt put URL file:b.txt open file b.txt for append write x to file b.txt  at 2 close file b.txt put URL

Re: Reading/Deleting Last Line Of File

2010-02-12 Thread J. Landman Gay
Kay C Lan wrote: On Sat, Feb 13, 2010 at 8:25 AM, Alex Tweedly a...@tweedly.net wrote: Could you try this in your multi-line msg box and let me know what it does on Mac ? put abcdefg CR into URL file:b.txt put URL file:b.txt open file b.txt for append write x to file b.txt at 2 close file

Re: Reading/Deleting Last Line Of File

2010-02-12 Thread J. Landman Gay
Kay C Lan wrote: On Sat, Feb 13, 2010 at 8:25 AM, Alex Tweedly a...@tweedly.net wrote: Could you try this in your multi-line msg box and let me know what it does on Mac ? put abcdefg CR into URL file:b.txt put URL file:b.txt open file b.txt for append write x to file b.txt at 2 close file

Re: Reading/Deleting Last Line Of File

2010-02-11 Thread Alex Tweedly
Jeff Massung wrote: Warren, I've read through most of these suggestions, but I'm surprised that the obvious hasn't been suggested yet (that I've seen): skip everything... Hasn't been suggested because it won't work. put the length of url file:myfile.txt into tEnd open file myfile.txt for

RE: Reading/Deleting Last Line Of File

2010-02-11 Thread Jim Bufalini
Alex Tweedly wrote: Jeff Massung wrote: Warren, I've read through most of these suggestions, but I'm surprised that the obvious hasn't been suggested yet (that I've seen): skip everything... Hasn't been suggested because it won't work. put the length of url file:myfile.txt

Re: Reading/Deleting Last Line Of File

2010-02-11 Thread Jeff Massung
On Thu, Feb 11, 2010 at 5:49 PM, Alex Tweedly a...@tweedly.net wrote: Jeff Massung wrote: Warren, I've read through most of these suggestions, but I'm surprised that the obvious hasn't been suggested yet (that I've seen): skip everything... Hasn't been suggested because it won't work.

Re: Reading/Deleting Last Line Of File

2010-02-11 Thread Richard Gaskin
Jeff Massung wrote: I'm still new to Rev, but in other languages this is dead simple: void truncate_huge_file(const char* filename) { FILE* fp = fopen(filename,wb); char bytes[200]; size_t new_len; // move to the end of the file, read 200 bytes fseek(fp, -200, SEEK_END);

Re: Reading/Deleting Last Line Of File

2010-02-10 Thread Warren Kuhl
Thanks for all the suggestions. I will look into trying some of them to see what works best for me. The file currently contains 105,750,304 records. I will report back my findings. Thanks, Warren On Tue, Feb 9, 2010 at 11:58 PM, J. Landman Gay jac...@hyperactivesw.com wrote: Jim Bufalini

Re: Reading/Deleting Last Line Of File

2010-02-10 Thread Kay C Lan
You mean you'll report back when you only have 105,750,303 records ;-) On Wed, Feb 10, 2010 at 9:06 PM, Warren Kuhl warrenk...@gmail.com wrote: Thanks for all the suggestions. I will look into trying some of them to see what works best for me. The file currently contains 105,750,304

Re: Reading/Deleting Last Line Of File

2010-02-10 Thread Jeff Massung
Warren, I've read through most of these suggestions, but I'm surprised that the obvious hasn't been suggested yet (that I've seen): skip everything... put the length of url file:myfile.txt into tEnd open file myfile.txt for text update seek to tEnd in file myfile.txt From here just back up a

Re: Reading/Deleting Last Line Of File

2010-02-10 Thread Brian Yennie
Jeff, This line: put the length of url file:myfile.txt into tEnd Loads the entire file into memory in order to get its length. - Brian ___ use-revolution mailing list use-revolution@lists.runrev.com Please visit this url to subscribe, unsubscribe

Re: Reading/Deleting Last Line Of File

2010-02-10 Thread Jeffrey Massung
On Feb 10, 2010, at 11:26 PM, Brian Yennie wrote: Jeff, This line: put the length of url file:myfile.txt into tEnd Loads the entire file into memory in order to get its length. That's a joke, right? :-( A freakin' OS call could get that just by touching an I-Node. Please, God,

Re: Reading/Deleting Last Line Of File

2010-02-10 Thread Brian Yennie
It's more a product of the syntax than anything. url file:myfile.txt is a container, and the length operates on it as such. URL containers are pretty darn handy in general, but this is one potential gotcha. You can use the detailed files to get information about a file, including its size in

Reading/Deleting Last Line Of File

2010-02-09 Thread Warren Kuhl
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? Thanks, Warren ___

Re: Reading/Deleting Last Line Of File

2010-02-09 Thread Till Bandi
doesn't that work?: delete line -1 of file myTextFile Till Am 09.02.2010 um 14:52 schrieb Warren Kuhl: 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

RE: Reading/Deleting Last Line Of File

2010-02-09 Thread Jim Bufalini
Warren, 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

Re: Reading/Deleting Last Line Of File

2010-02-09 Thread Warren Kuhl
Jim, 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

RE: Reading/Deleting Last Line Of File

2010-02-09 Thread Jim Bufalini
Warren, 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

Re: Reading/Deleting Last Line Of File

2010-02-09 Thread Warren Kuhl
Jim, Thanks for the explanationI will give this a try. Thanks! Warren On Tue, Feb 9, 2010 at 9:08 AM, Jim Bufalini j...@visitrieve.com wrote: Warren, 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

Re: Reading/Deleting Last Line Of File

2010-02-09 Thread Alex Tweedly
I don't think this will work, Jim. If you open a file for write, then it erases the entire content of the file first as the docs say (emphasis added)... The file to write to must be opened first with the open file command, and the mode the file was opened in must be write, append, or update.

Re: Reading/Deleting Last Line Of File

2010-02-09 Thread J. Landman Gay
Piggy-backing here: 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? It sounds like a big file, but Rev is pretty good

Re: Reading/Deleting Last Line Of File

2010-02-09 Thread Richard Gaskin
Would the seek command help? Presumably it would move the file pointer to the specified point without having to load the entire file into RAM. If you knew your lines were shorter than a given length, say 1000 chars, you could so something like: open file tFile for append seek relative

Re: Reading/Deleting Last Line Of File

2010-02-09 Thread Richard Gaskin
See why you shouldn't trust off-the-cuff code? Where I wrote: open file tFile for append ...I meant to write: open file tFile for update -- Richard Gaskin Fourth World Rev training and consulting: http://www.fourthworld.com Webzine for Rev developers: http://www.revjournal.com

RE: Reading/Deleting Last Line Of File

2010-02-09 Thread Jim Bufalini
Alex, It does work, just not exactly how I said to do it. ;-) You have to open the file for append*, instead of *write* and then write at a byte offset. So: open file filename for append write This is the EOF to file fileName at close file filename I just tested on an approximately 10kb

RE: Reading/Deleting Last Line Of File

2010-02-09 Thread Jim Bufalini
Jacque wrote: Worth a test anyway. I've used it on files that were several megs in size without a problem, but they weren't super huge, just kinda big. Hi Jacque, I made the suggestion I did because at 100 Million records plus, that's an awfully big read into memory just to delete the last

RE: Reading/Deleting Last Line Of File

2010-02-09 Thread Jim Bufalini
...@lists.runrev.com [mailto:use-revolution- boun...@lists.runrev.com] On Behalf Of Richard Gaskin Sent: Tuesday, February 09, 2010 2:10 PM To: How to use Revolution Subject: Re: Reading/Deleting Last Line Of File See why you shouldn't trust off-the-cuff code? Where I wrote: open file

Re: Reading/Deleting Last Line Of File

2010-02-09 Thread J. Landman Gay
Jim Bufalini wrote: Jacque wrote: Worth a test anyway. I've used it on files that were several megs in size without a problem, but they weren't super huge, just kinda big. Hi Jacque, I made the suggestion I did because at 100 Million records plus 100 million? Yes, well...I think I read the