title: How to replace a string of a file in unix
body: <p>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:</p>
  
  <p>Before: foo.txt</p>
  
  <pre><code>word1 word2 word3 'This the text that needs replacement' word4 word5
  </code></pre>
  
  <p>After: foo.txt</p>
  
  <pre><code>word1 word2 word3 'I have been replaced' word4 word5
  </code></pre>
  
  <p>Please note that the text 'This the text that needs replacement' is NOT constant and its content may vary.</p>