• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: search / replace in a text file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: search / replace in a text file


  • Subject: Re: search / replace in a text file
  • From: "Arthur J Knapp" <email@hidden>
  • Date: Tue, 13 Feb 2001 10:47:15 -0500

> Date: Tue, 13 Feb 2001 08:34:25 +1100
> Subject: Re: search / replace in a text file
> From: Shane Stanley <email@hidden>

> On 13/2/01 4:49 AM +1000, Jason Toews, email@hidden, wrote:
>
>> Oh, and don't even suggest the "split the file into
>> ... BEFORE ... line to be changed ... AFTER

> But you can do it in chunks. Assuming the bit you need to change is in the
> first 400 bytes, you could use something like this:

> set aFile to choose file
> set fileRef to (open for access aFile)
> set fileRef2 to (open for access file ((aFile as text) & "*") with write

Good stuff. :)

One comment, however, regarding the fact that fileRef2 is a new simple
text file. If you want to keep the original file's resource fork, you
may want to:

Duplicate fileRef, returning the new file's reference to fileRef2

Set fileRef2's length to 0, then perform the write operations.

You would then simply delete fileRef and rename fileRef2.


Another solution which I sometimes use is to create both a read
access and a write access to the same file, which I then use to
create read/write operations with the same line of code:

-- pseudocode:
--
write ( read fileReadAccess from x to kBuffSize ) to fileWriteAccess

The problem is making sure that you don't overwrite something that
you still have to read. (All in all, this is the least safe way to go
about it. It is better to use the temporary file method.)

--
{
Arthur J Knapp, of STELLARViSIONs ;

http://www.STELLARViSIONs.com ;

mailto:email@hidden ;

"...it's not my birthday,
it's not today..."
}


  • Prev by Date: Mount volume, slash problem
  • Next by Date: Stoping the script until "Enter" is pressed?
  • Previous by thread: Re: search / replace in a text file
  • Next by thread: Mount Volume problem (yes, another one)
  • Index(es):
    • Date
    • Thread