title: find and replace string in a file
body: <p>I'm trying to find and replace a string in a folder of files.</p>
  
  <p>Could someone possibly help me?</p>
  
  <p>My script is as follows:</p>
  
  <pre><code>#!/bin/bash
  OLD="This is a"
  NEW="I am a"
  DPATH="/home/user/test/*.txt"
  BPATH="/home/user/test/backup/foo"
  [ ! -d $BPATH ] &amp;&amp; mkdir -p $BPATH || :
  for f in $DPATH
  do
    if [ -f $f -a -r $f ]; then
      /bin/cp -f $f $BPATH
      sed "s/$OLD/$NEW/g" "$f"
     else
      echo "Error: Cannot read $f"
    fi
  done
  </code></pre>
  
  <p>Now this seems to find the string 'This is a' and replaces with 'I am a', but this only prints to screen.</p>
  
  <p>I need it to replace in the files themselves.</p>
  
  <p>Thanks</p>