I have to process a very large file (multi-GB) ...
Matching in huge files demonstrates a sliding buffer technique for matching patterns that might span block boundaries in large files. You could adapt it for doing search/replace.
Comment on Re: search/replace very large file w/o linebreaks