This is a question regarding linux in general, not only ubuntu,
I hope it's allowed posting questions regarding programming doubts.
Assuming using bash, having a configuration file like:
In which you can find multiple commented or uncommented lines of the param-foo, how can you comment all the uncommented param-foos except the very last active one, resulting in:param-a=aaaaaa
param-foo=first occurence <-- Replace
# param-foo=first commented foo <-- Commented: don't replace
param-foo=second occurence <-- Replace
param-foo=third occurence <-- Last active: don't replace
# param-foo=second commented foo <-- Commented: don't replace
# param-foo=first occurence <-- Replaced
# param-foo=commented foo <-- Left
# param-foo=second occurence <-- Replaced
param-foo=third occurence <-- Left
# param-foo=second commented foo <-- Left
1. How to do it with only one desired param?
(only param-foo in the example above)
2. How to do it with all multiple active params at once?
(param-foo + param-x in the example above)
I'm really puzzled