I have two almost identical config files in two different directories## file1.conf ##tunnel:    enable: true    interval: 20    public: falseloop:    enable: false    interval: 20    public: falselink:    enable: true    interval: 20    public: false## file2.conf ##tunnel:    enable: true    interval: 20    public: falseloop:    interval: 20    enable: false    public: falselink:    enable: true    interval: 20    public: falseNow I want to change enable: false to enable: true but only for the loop section in both files. How can I do this using just one set of commands for both files?
Changing config files with awk/sed
sed;awk
This can be done with an inplace edit using sed -i.sed -i '/^loop:/,/^$/ { s/enable:.*$/enable: true/ }' file1.conf file2.confThe command breaks down into two main parts:/^loop:/,/^$/ { .... }This means we limit the stuff inside the {...} to the section that begins with loop: and ends with a blank line.Inside that we haves/enable:.*$/enable: true/Which simply ensures the enable: line is set to true.The result is that we rewrite file1.conf and file2.conf so that the section beginning loop: and ending with a blank line has any enable line rewritten to enable: true