Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to append string in bash script using sed?

Hello I am trying to make a script to edit chrome flags on mac using a bash script. This script is to set max SSL to TLS1.3 on chrome. However, I am having some issues with sed. Here is what my command looks like:

sed -i '.bak' -e 's/{\"browser\".*origin\":\"\"\}/\"browser\":\{\"enabled_labs_experiments\":\[\"ssl-version-max@2\"\],\"last_redirect_origin\":\"\"\}/g' "./Local State"

The goal is to append

"enabled_labs_experiments":["ssl-version-max@2"]

to this

{"browser":{"last_redirect_origin":""}

to make it looks like this

{"browser":{"enabled_labs_experiments":["ssl-version-max@2"],"last_redirect_origin":""}

Not sure what's wrong with my command but any help in achieving this is really appreciated or just pointing me in right direction would help greatly.

Thanks!

like image 762
LuciDroid Avatar asked Jun 08 '26 17:06

LuciDroid


1 Answers

sed -i '.bak' -e 's|\(\"browser\"\):{\(\".*origin\":\"\"\)}|\1:{\"enabled_labs_experiments\":[\"ssl-version-max@2\"],\2}|'

The trick is to use the \( and \), to define two groups, and use \1 and \2 in your substitution to represent these groups. BTW, your curly brackets don't match in your examples...

like image 131
blackghost Avatar answered Jun 11 '26 12:06

blackghost