I need to remove a lot of text from the middle of a text file. I have a Applescript that can find my character offset of my desired string (start and end), but when I work on a file that is over 1mb, the Script Debugger hangs.
So can someone give me a script that would be able to delete text from a file from a certain character offset, to another offset, and then either return it or write a new file? I imagine a shell script would be a lot better at doing this but I don’t know much shell scripting.
set myFile to alias "HardDrive:Users:yourmama:Desktop:FooBarFile.inx" set myFileString to read myFile -->file is over 1million characters easily set andhOffset to offset of "andh=" in myFileString --there could be a couple sets, but just find the first set andhOffset to andhOffset + 5 -->usually about 650,000+ --we must include the ...andh="... set my1 to (characters 1 thru andhOffset of myFileString) as string set secondPart to characters -4092 thru end of myFileString as string --just read the back section to make it faster than reparsing whole thing, this stuff is always near the end set endOffset to offset of "rc_dhyfe" in secondPart set endOffset to endOffset - 4092 -->s/b a neg number, -3895 set endOffset to endOffset - 9 --must include ..." Self="rc_dhyfe... set my2 to (characters endOffset thru -1 of myFileString) as string set newINXString to my1 & my2 as string --write a new file