title: shell bash, cat file whilst using sed to replace text
body: <p>With the help of SO I have been able to correct my sed command so I can use variables (was using ' instead of " and wasn't using g for global).</p>
  
  <p>However, I am struggling to get the command to work correctly.</p>
  
  <p>To give you some context, I have a file containing numerous lines of text and some line contain one or more tags. these tags are in the following format:</p>
  
  <pre><code>[#$key#] - i.e #[#] is used to indicate the presence of a key
  </code></pre>
  
  <p>Then I have an internal array object which stores a string value which contains each key and a corresponding value in the following format:</p>
  
  <pre><code>$key=$value
  </code></pre>
  
  <p>What I am trying to do is to cat my file containing the tags at the same time as using a global sed replace to swap the $key for the corresponding value within the array object.</p>
  
  <p>The problem I have is that my grep/sed command is not replacing any of the text and I can't figure out why. </p>
  
  <p>here is my code:</p>
  
  <pre><code>for x in "${prop[@]}"
  do
       key=`echo "${x}" | cut -d '=' -f 1`
       value=`echo "${x}" | cut -d '=' -f 2`
  
  
      # global replace on the $MY_FILE
      cat $MY_FILE | sed "s|\[#${key}#\]|${value}|g" &gt; ${TEMP_MY_FILE}
      cat $TEMP_MY_FILE &gt; $MY_FILE
  
   done
  </code></pre>
  
  <p>I thought about using sed -i, but my version doesn't seem to support-i </p>