I want to edit some config files on in the CLI without a wysiwyg editor but instead using sed.
Is there a best practice for doing that?
Here are a few examples of what I mean:
Config file example 1
A line in the config file could be this:
foo_option /bar/baz
And after editing it should look like this:
#foo_option /bar/baz
foo_option /new/opt
Config file example 2
A line in the config file could be this:
foo_option=/bar/baz
And after editing it should look like this:
#foo_option=/bar/baz
foo_option=/new/opt
I'm think that the stream editor sed is the tool of choice, I've already experimented with it:
sed -e 's/\(^foo_option .*$\)/#\1/' /path/to/conf.file
And:
sed -e 's/^foo_option .*$/foo_option /new/opt/' /path/to/conf.file
But how can I make both changes (two lines, one commented out and one with the new content) at the same time?
And would it really be the best practice with sed at all?