Re: Setting contents of a large file to a variable.
Re: Setting contents of a large file to a variable.
- Subject: Re: Setting contents of a large file to a variable.
- From: Christopher Nebel <email@hidden>
- Date: Thu, 25 Nov 2004 13:36:55 -0800
On Nov 25, 2004, at 6:55 AM, Dan Belfiori wrote:
On Nov 25, 2004, at 12:36 AM, Rob Stott wrote:
The easiest change to your existing script would be to process the
file in
chunks.
Andrew's method works and is the way most folks get round this in
AppleScript. Depending on what you want to do, it may also be worth
your while investigating how to use 'do shell script' to manipulate a
text file (read up on Unix commands, cat, grep, tr and sed).
The advantage of shell scripts is that you edit the text file instead
of trying to read, edit and rewrite it. I know very little of unix
commands...but this one did it for me.
perl -pi -e s/OldText/NewText/g file.txt
It uses perl to find and replace text in a text file.
Sort of. In reality, perl -i is reading the whole file, writing out a
new one, and then deleting the old file. It's not significantly more
efficient in terms of the base operations, but it does mean that perl
is doing all the bookkeeping (reading in chunks, writing, etc.) for
you.
A lot of people have this idea that there's some sort of magical way to
alter a huge file without rewriting the entire thing, and there really
isn't -- it's an inherent limitation of how just about any file system
works. There are obviously ways that make you write more or less code
to do it, but if you want to, say, delete the first three lines of a
40MB file, you're going to have to read and write 40MB of data.
--Chris Nebel
AppleScript Engineering
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden