# If you'd like to omit non-matching lines from the result; add ';d' to the end of the expression.
sed -E 's/^(wsrep_provider_options(?!.*\bgcache.size\b).*)('$)/\1; gcache.size=4G\2/gm;t' <<< "wsrep_provider_options='gmcast.segment=0; ist.recv_addr=tcp://db7; ist.recv_bind=tcp://0.0.0.0; socket.ssl_cert=/etc/mysql/wsrep/ssl/gmnode.pem; socket.ssl_key=/etc/mysql/wsrep/ssl/gmnode.key; socket.ssl_ca=/etc/mysql/wsrep/ssl/gmca.pem'
wsrep_provider_options='gmcast.segment=0; ist.recv_addr=tcp://db7; ist.recv_bind=tcp://0.0.0.0; socket.ssl_cert=/etc/mysql/wsrep/ssl/gmnode.pem; socket.ssl_key=/etc/mysql/wsrep/ssl/gmnode.key; socket.ssl_ca=/etc/mysql/wsrep/ssl/gmca.pem; gcache.size=4G'
wsrep_provider_options='gcache.size=4G; gmcast.segment=0; ist.recv_addr=tcp://db7; ist.recv_bind=tcp://0.0.0.0; socket.ssl_cert=/etc/mysql/wsrep/ssl/gmnode.pem; socket.ssl_key=/etc/mysql/wsrep/ssl/gmnode.key; socket.ssl_ca=/etc/mysql/wsrep/ssl/gmca.pem'"
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for SED, please visit: https://www.gnu.org/software/sed/manual/html_node/The-_0022s_0022-Command.html