title: Replacing strings with special characters with linux sed
body: <p>I've read lots of posts to understand how to correctly escape white spaces and special characters inside strings using sed, but still i can't make it, here's what i'm trying to achieve.</p>
  
  <p>I have a file containing the some strings like this one:</p>
  
  <pre><code> JAVA_OPTS="$JAVA_OPTS -Dorg.apache.catalina.jsessionid=some_value"
  </code></pre>
  
  <p>and i'm trying to replace 'some_value' using the following:</p>
  
  <pre><code>sed -i "s/^\(JAVA_OPTS=\"\$JAVA_OPTS[ \t]*-Dorg\.apache\.catalina\.jsessionid*=\s*\).*\$/\1$DORG_APACHE_CATALINA_JSESSIONID/" $JBOSS_CONFIGURATION/jboss.configuration
  </code></pre>
  
  <ul>
  <li>$JBOSS_CONFIGURATION is a variable containing an absolute Linux path.</li>
  <li>jboss.configuration is a file i'm pointing as the target for replace
  operations.</li>
  <li>$DORG_APACHE_CATALINA_JSESSIONID contains the value i want instead
  of 'some_value'.</li>
  </ul>
  
  <p>Please note that the pattern:</p>
  
  <pre><code>JAVA_OPTS="$JAVA_OPTS -D
  </code></pre>
  
  <p>Is always present, and org.apache.catalina.jsessionid is an example of a variable value i'm trying to replace with this script.</p>
  
  <p>What's missing/wrong ? i tried also escaping whitespaces using \s without success,
  and echoing the whole gives me the following:</p>
  
  <pre><code>echo "s/^\(JAVA_OPTS=\"\$JAVA_OPTS[ \t]*-Dorg\.apache\.catalina\.jsessionid*=\s*\).*\$/\1$DORG_APACHE_CATALINA_JSESSIONID/"
  
  s/^\(JAVA_OPTS="$JAVA_OPTS[ \t]*-Dorg\.apache\.catalina\.jsessionid*=\s*\).*$/\1/
  </code></pre>
  
  <p>is echo interpreting the search pattern as sed does ?</p>
  
  <p>any info/help/alternative ways of doing it are highly welcome,
  thank you all</p>