I have a text file and I'm trying to find all instances of
Word1 Word2 Word3 in a text file and replace it with
Word4 Word2 Word5. Word2 is unknown string but the rest of the words are known.
Here is what I have tried so far
I have a string
(...) foobarfoo (...) and I want to replace it with
(...) hatbarcar (...)
sed -i 's/foo.*foo/hat.*car/g' data.txt
but the result I get is
(...) hat.*car (...)
So the wildcard is finding the word string I want but I then want to use this same wildcard to write the string which replaces the old one.
Is this possible/anyone have any suggestions?