I have this settings.conf file in linux defined as follows:
JavaScript
x
Section A
first-setting = value
# second-setting = off
third-setting = value
Section B
first-setting = value
# second-setting = off
third-setting = value
I would like to uncomment # second-setting = off
of Section A only (first occurrence), and set the value to on.
So far, I have this:
cat settings.conf | sed '/^# second.*/ {s/^#//;s/off/on/}'
Any tips?
Advertisement
Answer
Is this what you had in mind?
JavaScript
sed '0,/#/s/#(.*) off/1 on/' settings.conf
Or if your on osx with non-gnu sed:
JavaScript
sed '1,/#/s/#(.*) off/1 on/' settings.conf