A more complex replace into a file?
I run into this type of issue all of the time and haven't found a great way to deal with it.
I want to place gcache.size=3G into a file and it needs to replace or add depending on the situation:
Situation 1: Append to this line
wsrep_provider_options="cert.optimistic_pa=no"
wsrep_provider_options="cert.optimistic_pa=no;gcache.size=3G;"
Situation 2: append but don't put in double ;;
wsrep_provider_options="cert.optimistic_pa=no;"
wsrep_provider_options="cert.optimistic_pa=no;gcache.size=3G;"
Situation 3: If commented out, just add a new line with the value we want set
#wsrep_provider_options="cert.optimistic_pa=no"
wsrep_provider_options="gcache.size=3G"
Situation 4: If doesn't exist, add it
<line doesn't exist>
wsrep_provider_options="gcache.size=3G"
Situation 5: if it's a different value, replace
wsrep_provider_options="cert.optimistic_pa=no;gcache.size=5G;"
wsrep_provider_options="cert.optimistic_pa=no;gcache.size=3G;"
Is there a clever way to do this?