title: Optimize shell script for multiple sed replacements
body: <p>I have a file containing a list of replacement pairs (about 100 of them) which are used by <code>sed</code> to replace strings in files.</p>
  
  <p>The pairs go like:</p>
  
  <pre><code>old|new
  tobereplaced|replacement
  (stuffiwant).*(too)|\1\2
  </code></pre>
  
  <p>and my current code is:</p>
  
  <pre><code>cat replacement_list | while read i
  do
      old=$(echo "$i" | awk -F'|' '{print $1}')    #due to the need for extended regex
      new=$(echo "$i" | awk -F'|' '{print $2}')
      sed -r "s/`echo "$old"`/`echo "$new"`/g" -i file
  done
  </code></pre>
  
  <p>I cannot help but think that there is a more optimal way of performing the replacements. I tried turning the loop around to run through lines of the file first but that turned out to be much more expensive. </p>
  
  <p>Are there any other ways of speeding up this script?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Thanks for all the quick responses. Let me try out the various suggestions before choosing an answer.</p>
  
  <p><strong>One thing to clear up:</strong> I also need subexpressions/groups functionality. For example, one replacement I might need is:</p>
  
  <pre><code>([0-9])U|\10  #the extra brackets and escapes were required for my original code
  </code></pre>
  
  <p>Some details on the improvements (to be updated):</p>
  
  <ul>
  <li><strong>Method: processing time</strong></li>
  <li>Original script: 0.85s</li>
  <li><code>cut</code> instead of <code>awk</code>: 0.71s</li>
  <li>anubhava's method: 0.18s</li>
  <li>chthonicdaemon's method: 0.01s</li>
  </ul>