title: Sed error: bad flag in substitute command: 'U'
body: <p>I'm new in bash script and trying to replace some words in my file using sed. Following is the bash I use in my script:</p>
  
  <pre><code>sed -i '' "s/&lt;pre&gt;.*&lt;\/pre&gt;/&lt;pre&gt;($NEWNAME) $MD5&lt;\/pre&gt;/"~/Desktop/replace.html
  </code></pre>
  
  <p>And  I got error message saying: <code>bad flag in substitute command: 'U'</code>. I use double quote because I need to put variables in. </p>
  
  <p>My environment is Mac.</p>
  
  <p>======================================    </p>
  
  <p>1.Turns out I forgot to leave a space between replace string and file name. Which led to the result always showing: <code>bad flag in substitute command: '~'</code>. It works now.</p>
  
  <p>2.The reason is I used <code>MD5=$(md5 path)</code> to create MD5 value which gets the reault of <code>MD5 (path) *****</code>, and the path contains <code>/</code> which breaks the regex. After changing <code>MD5=$(md5 -q path)</code>, it will be ok.</p>