posted 11 years ago
If you want to know how many lines are in a file, you read that file, a line at a time, and keep a count as you go.
If you want to edit the file, you read the file in, change the lines you want to change, and write the file back out.
You can do both at the same time if the editing doesn't depend on the number of lines. If it does depend on it, then you'll have to make two passes.