0

I'm finally learning how to use sed to edit configs while installing Ubuntu(Server/Desktop). After much gnashing of teeth and searching about for the proper syntax to not remove the "(comment double-quotes with exactly one blank space afterward(real comments)), as opposed to the lines that have potential code to toggle(zero blank spaces or two blank spaces for indented lines of code) in the /etc/vim/vimrc file, I figured out how to get things working with the following command:

$ sudo sed -i.orig '/^\" [a-zA-Z]\|^"set compatible\|^\" let g:skip_defaults_vim = 1b/! s/^\"//' /etc/vim/vimrc

Will the Guru's or apprentices, alike, please let me know if I could have done this better(tighter/cleaner/etc.)?

Example using awk for the same result?

Thank you.

1 Answers1

1

Use the \1 numbered capture variables in the change destination like so s/^([[:space:]]*)"[[:space:]]*(let .*)/\1\2/

Also use sed 'your change;another change' file > file.tmp$$ && mv file.tmp$$ file

It's the "safer" and portable way to change files in place than sed -i ...

For dotfiles like ~/.vimrc under ~ and conf files under /etc, use git to save them locally. etckeeper is great for /etc management with git.

Some people use augeas to edit conf files, or even chef/puppet to manage them automatically.