• 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: Shane Stanley <email@hidden>
  • Date: Tue, 13 Feb 2001 08:34:25 +1100

On 13/2/01 4:49 AM +1000, Jason Toews, email@hidden, wrote:

> Oh, and don't even suggest the "split the file into (1)the text BEFORE the
> line to be changed, (2)the line to be changed, and (3)the text AFTER the
> line to be changed" thing. These files are bloody huge. Too big to read
> everything AFTER the offending line into a variable.

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
permission)
set eof fileRef2 to 0
set firstBit to read fileRef for 4000
-- make your changes to firstBit
write firstBit to fileRef2
set chunkSize to 16384
repeat
try
set aChunk to read fileRef for chunkSize
on error -- end of file
exit repeat
end try
write aChunk to fileRef2
end repeat
close access fileRef
close access fileRef2

--
Shane Stanley, email@hidden


  • Prev by Date: Re: AppleScript crashes constantly
  • Next by Date: Applescript and FileMaker
  • Previous by thread: search / replace in a text file
  • Next by thread: Re: search / replace in a text file
  • Index(es):
    • Date
    • Thread