sed reads a stream and applies editing rules. A substitution has a pattern, replacement and optional flags. The global flag replaces repeated matches on a line. Redirect transformed output to a new file when the input must remain unchanged.
In-place editing has a different purpose and violates that requirement even if the resulting text is correct. These tasks include repeated values and a backup key so a partial rewrite is visible. In s/old/new/g, the slashes separate the pattern, replacement and flag. Without g, sed changes only the first match on each line. A substitution can succeed while leaving unrelated lines unchanged. Read the transformed output before saving it, then compare the original when preserving source evidence is part of the request.