The only way to process text files is to read them sequentially, start to finish. Text files generally don't allow for random access. One trick I've used in the past with text files which must be read frequently is to set up a fixed-length record index file which contains line numbers and the offset in the file where the line number begins. This only speeds up frequently reading the file, not writing. You have to completly rewrite the file if the new text is longer or shorter than the existing text. For example you can't just simply overwrite the word "the" with the word "them". But if you want to overwrite "the" with anothr 3-letter word then you can just overwrite it, assuming you know the offset of the start of the word.
A better answer to your question will depend on what you mean by "process the file". It might mean that you need to read a block of lines into memory, process them, and rewrite them to another file, then repeat that until the entire file is processed.