Changing 1234 to 3210 is very easy, but how about changing 12 to 1235?
Before thinking about programming details, you'll need to consider file structures and what you exactly want to do.
I presume that each line is terminated with <CR><LF> without hidden spaces. Then you can easily replace a line with a different one of the same length. But to change the length, you'll need to copy and rewrite the whole file. Consider if this apprpriate or if you should use a different file structure.