SED - Change - Change next-to-last case
sed
's/\(.*\)foo\(.*foo\)/\1bar\2/'