in reply to Edit a text file line by line

You need to open a file to write and print the changes to that file. Best method I know of is saving your changes to an array, opening a temp file, printing the array to the file and then renaming it to the original.

Software speaks in tongues of man.
Stop saying 'script'. Stop saying 'line-noise'.
We have nothing to lose but our metaphors.