New to python programming so bare with me but I haven't quite seen an easy way to do this and looking for some suggestions.
I want to be able to replace some contents of an exisiting file either by both inserting new statements or modifying/replacing new ones withiout touching or modifying the other contents of the file. I will know ahead of time by whats in the property what I will be searching for. So It would be nice if the program would be flexible enough to figure out what to look for as well based on what new parameters are to be set from the property file.
Let me give a real-world example.
We have programs with start-scripts. For example. start.sh. (this is only an example and not actual so ignore the typos. Its only there to illustrate my question"
Inside start.sh there may be the following statements:
What I want to be able to do is have a property file that says contains additional path and classpath variables that I want to append do it. In the future this property file could just have DB_DRIVER information or another value thats not listed in the example.
So I'll need to be able to read the file and recognize that I've reached the classpath statement as well as others and modify it appending my contents to it (either before or after) the existing values, while not losing them.
Second I may want to be able to place a newline of statements anywhere in the file or after a certain line. For example, I may want to insert new lines into the file after DB_DRIVER or before ./startup and will pull those values out of this property file.
Any suggestions or code snippets is greatly appreciated.