For text files I usually read the file in with textread, and then run through for the lines I'm looking for using fgetl() which can be used to examine each line individually. I like to run this through a while loop since I don't know how long the file is, and I just look for specific strings to edit.
After that is done I print everything out using fprintf, when I have to use strings. I have admittedly not written out a large block of text before, but I would imagine if you put the line read, lined edit, and line print commands in a loop then you can read and write your files all within a loop. This is likely not the most efficient way.
