i think you have the right idea. whenever im manipulating a file like this, i read one in (read only) and create a new one (write only), ive never used the same file for read/write (replacing) like you want to do, but it can be done either way of course. the only real thing your missing is writing the line to the file. a simple print statement is all you need. however, i would write it using the following pseudocode:
Code:
- open "IN" file for read
- open "OUT" file for write (create it)
- while not EOF:
-- read "IN" file and save to "$line"
-- if "$line" matches the pattern:
---- set "$line" to: "#" + "$line"
-- print "$line" to "OUT" file
- close files
in either case (whether the line matched the pattern or not), the line is still written to the output/new/modified file. does this help?