SED - Change - Change lines which contain a specific string

Substitute “foo” with “bar” ONLY for lines which contain “baz”.

sed '/baz/s/foo/bar/g'