I am looking for a generic command line solution that would allow me to add or modify a configuration option inside a config file (ini like format).
Most linux configuration files use a INI like format, with # and ; as comment and with option=value.
Mainly I am looking for something that would take filename, option and value, and that will change the config to match this.
I want to use this to write some auto-deployment scripts. I have no problem on using tools that are not installed by default on Debian or Ubuntu as long they do exist in the default distribution repositories (as I can do an apt-get install xxx, if needed).
Example: change-config /etc/default/nginx ULIMIT '"-n 4096"'
The expected result would be to have ULIMIT="-n 4096"
inside the nginx file. Obviously if it does already exists and have the same value, it should do nothing. If it exists, commenting the old line would be fine and adding the new one.
As a note, these config files can have spaces/tabs between parameters so if you have ULIMIT = "..."
is still the same command. That's why I was looking for something better than sed as there are plenty of corner cases to evaluate.
Also, I don't want to reinvent the wheel, and I doubt that I am the first one to look for a solution to this kind of problem.