title: What is the correct sed in-place string replacement syntax?
body: <p>I'm trying to replace a line in a file and here is my current shell script:</p>
  
  <pre><code>sed -i "s%$line%$line_formatted%g" $file_source
  </code></pre>
  
  <p>Whenever I try to replace <code>$line</code> with <code>$line_formatted</code> I get this error:</p>
  
  <pre><code>sed: -e expression #1, char 81: unknown option to `s'
  </code></pre>
  
  <p>I was just wondering what the correct syntax would be?</p>
  
  <p>Giving the below comment a try, it still doesn't replace the text. Here is the code I used:</p>
  
  <pre><code>echo "Here is line: "$line
  echo "Here is line_formatted: "$line_formatted
  
  # sed -i "s%$line%$line_formatted%g" $topicJRXML_file_source
  
  awk -v old="$line" -v new="$line_formatted" '
  s=index($0,old) { $0 = substr($0,1,s-1) new substr($0,s+length(old)) }
  ' $topicJRXML_file_source
  
  cp "$topicJRXML_file_source" "$topicJRXML_file_destination"
  echo "Here is line after awk: "$line
  </code></pre>
  
  <p>And this is my console output:</p>
  
  <pre><code>Here is line:  &lt;property name="adhoc.display" value="Awk Test"/&gt;
  Here is line_formatted:  &lt;property name="adhoc.display" value="$R{CUSTOM.Awk_Test.LABEL}"/&gt;
  Here is line after awk:  &lt;property name="adhoc.display" value="Awk Test"/&gt;
  </code></pre>