Re: search / replace in a text file
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