in reply to How do I modify a line within the file itself?

Kindly let me also offer the following bit of “battlefield experience,” which by-the-way will also serve to make your task much easier:

Never actually try to modify a [flat ...] file “in place!”

Instead, always write such logic so that it reads the existing file as input, and writes “the next ‘generation’ of that file” as output.   I-f the operation succeeds, you can now rename the files ... perhaps even using a scheme like the logrotate command does, or, what-the-hell, just using logrotate ... so that both the “old” and the “new” file remain.

The advantages are obvious:   “if something goes wrong, you’re not scroo-oo-ood.”   You can just run the command again.   And if the defect does not rear its ugly head until some time later ... as ugly defects so-often do ... you still might not be scroo-oo-ood.   The edits that you made were non-destructive.

And while we are on this subject, here is another battlefield suggestion:   “if the files in question are not of some titanic size, consider turning the directory-in-question into a git repository.”