After some googling around I found out that the sed command is all I need. To be honest though, the flags of this command seem impossible to comprehend. All I want is to do is replace a single-quoted string of a file with another one. word1, word2 and so on are not single/double quoted whatsover. Example:
Before: foo.txt
word1 word2 word3 'This the text that needs replacement' word4 word5
After: foo.txt
word1 word2 word3 'I have been replaced' word4 word5
Please note that the text 'This the text that needs replacement' is NOT constant and its content may vary.