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?
foo_option=/bar/baz? Does the file only contain that one line or else just one instance of it? – Nasir Riley Dec 01 '21 at 23:512021-12-01: Changed setting to this.– Giacomo1968 Dec 02 '21 at 03:49sed -e 's/\(^foo_option .*$\)/#\1/' /path/to/conf.file && sed -e 's/^foo_option .*$/foo_option /new/opt/' /path/to/conf.file. The reality is this all seems fine. There is no universal “best practice” for doing stuff like this but whatever works best for you. – Giacomo1968 Dec 02 '21 at 03:51nanoand do this and that!" Its better for me to copy text and paste it in terminal... And that's why i'm asking for the 'best practice' (and maybe most readable) – ingank Dec 02 '21 at 18:49