title: How to replace strings avoiding making second order replacements?
body: <p>I have a text file and I want to make a text replacement. However, my problem this time is that the new text also includes text that originally exists in the original file and that appears in the hash of replacements.</p>
  
  <p>How can I replace text but only once per line, avoiding making "second order" replacements?</p>
  
  <p>Normally I do replacements with sed where I use col1 and col2 file for the replacement. col1 has the original string to replace; col2 the new one. </p>
  
  <h3>input file:</h3>
  
  <pre><code>ID1 X1 X2 X3
  ID2 X3 X4 X5
  </code></pre>
  
  
  
  <pre><code>col1    col2 of "hash" used for replacement:
  X1      X2 X3
  X2      X7
  X3      X8
  </code></pre>
  
  <h3>output after replacement with sed</h3>
  
  <pre><code>ID1 X7 X3 X7 X8
  ID2 X3 X4 X5
  </code></pre>
  
  <h3>Expected output</h3>
  
  <pre><code>ID1 X2 X3 X7 X8
  ID2 X8 X4 X5
  </code></pre>
  
  <h3>bash command used</h3>
  
  <pre><code>paste col1 col2 | while read n k; do sed -i \"\" \"s/$n/$k/g\" input; done
  </code></pre>