i need to replace with sed command this lines:
;[homes]
; browseable = no
In this lines:
[homes]
browseable = yes
sed -e 's/^; *//'
, unless your example doesn't cover all cases.
There are lots of ways to fix the two lines shown. It gets a little trickier if you consider that this is ini-file format and there could be other sections which contain browseable
and other sections than [homes]
which should not be edited.
sed -e '/^;\[homes]/,/^;*\[/{
s/;\[homes]/[homes]/
s/^; *browseable.*/browseable = yes/
}'
Given the input file:
;[alerts]
; browseable = no
;[homes]
; browseable = no
; alternatives = no
;[houses]
; browseable = no
[mezzanine]
; browseable = no
alternatives = yes
The output from the above script is:
;[alerts]
; browseable = no
[homes]
browseable = yes
; alternatives = no
;[houses]
; browseable = no
[mezzanine]
; browseable = no
alternatives = yes
You can use awk
to do the changes.
awk '{sub(/^;[ ]*/,"")} /browseable/ {$3="yes"}1'
[homes]
browseable = yes
Given data from Jonthan
awk '/homes/ {sub(/^;[ ]*/,"");f=1} f && /browseable/ {sub(/^;[ ]*/,"");$3="yes";f=0}1' file
;[alerts]
; browseable = no
[homes]
browseable = yes
; alternatives = no
;[houses]
; browseable = no
[mezzanine]
; browseable = no
alternatives = yes
Or like this:
awk '/homes/ {$0="[homes]";f=1} f && /browseable/ {$0="browseable = yes";f=0}1' file
This will also work,
sed 's/^;//g;s/^ *\(.*\)/\1/g;s/no/yes/g' file