python - Replace multiline text in file using regex on Linux -
i need replace multiline text in config file. can use sed (busybox v1.21.1), perl (revision 5 version 14 subversion 2) or python (2.7).
the file can have 2 formats: a)
"is_managed": false, "local_profile_id": 15191724, "name": "first user" }, **"session": { "restore_on_startup": 4, "restore_on_startup_migrated": true, "urls_to_restore_on_startup": [ "http://alamakota/" ] }** }
or b)
"is_managed": false, "local_profile_id": 15191724, "name": "first user" }, **"session": { "restore_on_startup_migrated": true, }** }
i want change this:
"is_managed": false, "local_profile_id": 15191724, "name": "first user" }, "session": { "restore_on_startup": 4, "restore_on_startup_migrated": true, "urls_to_restore_on_startup": [ "http://192.168.0.100" ] } }
may want parse json first , encode json if needed
use json::xs; $rh_data = decode_json($json_string); #then updated values accesing $rh_data->{xx}{yy} = 'new value'; #and encode json $json_data = encode_json($rh_data);
Comments
Post a Comment