title: Awk replace string in line
body: <p>NOTE:
  This question looks like a <a href="https://stackoverflow.com/questions/39273660/awk-sed-replace-in-each-line-with-previous-string-in-the-line/39273912#39273912">previously posted one</a>, but as mentioned in the comments, it turned out to be a <a href="https://meta.stackexchange.com/questions/43478/exit-strategies-for-chameleon-questions">chameleon question.</a> 
  I accepted the answer, and I'm posting here the same problem but with slightly different "solution conditions".</p>
  
  <hr>
  
  <p>I have a file <code>test.txt</code> like this (but containing many more lines)</p>
  
  <pre><code>/foo/bar/how /SOME_TEXT_HERE/hello
  /foo/bar/are hello/SOME_OTHER_TEXT
  /foo/bar/you hello
  </code></pre>
  
  <p>I want to get this output:</p>
  
  <pre><code>/foo/bar/how /SOME_TEXT_HERE/how
  /foo/bar/are are/SOME_OTHER_TEXT
  /foo/bar/you you
  </code></pre>
  
  <p>I have tried this:</p>
  
  <pre><code>while read line
  do
  bla=$(echo $line | cut -f4 -d"/" | cut -f1 -d" ")
  sed -i "s/hello/$bla/" test.txt
  done &lt;test.txt
  </code></pre>
  
  <p>But the output is:</p>
  
  <pre><code>/foo/bar/how /SOME_TEXT_HERE/how
  /foo/bar/are how/SOME_OTHER_TEXT
  /foo/bar/you how
  </code></pre>
  
  <p><strong>NOTE</strong>:</p>
  
  <p>I would like the solution to:</p>
  
  <ol>
  <li><p>allow me to define a variable (here, <code>bla</code>) that I will define manually and differently from one file to the other (so not using sthg like basic field position), but using <code>cut</code> or other command as in my example)</p></li>
  <li><p>replace a specific string somewhere else in the line by this variable (so not a field position like <code>$2</code>, but really something like <code>s/hello/$bla</code>)</p></li>
  </ol>
  
  <p>I'm not sure of this is possible though (obviously I don't know how to do this by myself...), but thanks for your time trying! :)</p>