Shell script or AS to remove text from char x to char XX

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.

Thanks, Chris

Applescript version:

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

Think I have it. This is more direct since I know what the text is before and after my text string. It would still be nifty to have an funtion that will work on the offset of a char.

sed ‘s/andh=“.*” Self=“rc_dhyfe/andh=”" Self="rc_dhyfe/g’ /Users/chris/Desktop/file.txt

the andh=“.*” Self="rc_dhyfe is the search string with period asterisk being wildcard text
the second part is the string with all wildcard text removed.