I want
oy 1 x 1 x 1
1 x 1 x 1
to become
oy 1 y 1 y 1
1 x 1 x 1
(basically, replacing x by y if the line starts with oy, reusing y).
I have tried
echo "oy 1 x 1 x 1" | sed -E "s/(o(.)(.*))x/\1\2/g"
echo "oy 1 x 1 x 1" | perl -pe "s/(?<=o)(.)(.*)x/\1\2\1/g"
echo "oy 1 x 1 x 1" | perl -pe "s/o(.)(.*)\Kx/\1/g"
but each replaces only the last occurence.
These non-greedy variants
echo "oy 1 x 1 x 1" | perl -pe "s/(?<=o)(.)(.*?)x/\1\2\1/g"
echo "oy 1 x 1 x 1" | perl -pe "s/o(.)(.*?)\Kx/\1/g"
replace only the first occurence.
What else can I try?