On Sat, Jun 29, 2024 at 07:43:47 -0400, Dan Ritter wrote: > The option "g" means that said should do this multiple times if > it occurs in the same file (globally, like grep) instead of the > default behavior which is to find the first match and just > change that.
The g option in sed's s command means it will apply the substitution multiple times per *line*. Not per file. It always applies multiple times per file, unless you restrict the line range with a prefix. hobbit:~$ printf 'foo foo\nfoo foo\n' | sed s/foo/bar/ bar foo bar foo hobbit:~$ printf 'foo foo\nfoo foo\n' | sed s/foo/bar/g bar bar bar bar