[sed] Replace the first occurrence on each line

Created on November 30, 2026

Leave off the g flag to replace only the first match on each line. The command below changes the first foo to bar.

printf 'foo foo foo\n' | sed 's/foo/bar/'
bar foo foo
Bash Shell command sed