samedi 18 avril 2015

Nth string match and then delete following string and put a new string instead by sed

I have this file:



"Max": 10,
"Enable": true,
"Min": 2,
"Enable": true,
"Retries": 5,


I want to change the second occurrence Enable value by deleting all after "Enable": and put the value I need. I don't care which value is right now in "Enable" just to replace even if I replace with the same string.


I used this command:



sed -re 's/("Enable":)[^:]/\1 false,/2' file > newfile


But the result I get:



"Max": 10,
"Enable": true,
"Min": 2,
"Enable": false,true,
"Retries": 5,


I need it using sed command if it possible.


Thank you all!


Aucun commentaire:

Enregistrer un commentaire