title: sed to replace // with /* */ comments EXCEPT when // comments appear within /* */
body: <p>The problem I am facing is with an ANSI compiler that requires C style comments.</p>
  
  <p>So I am trying to convert my existing comments to comply with the C standard ISO C89.</p>
  
  <p>I am looking for a SED expression to replace // comments with /* comments EXCEPT when // comments appear within /* */ comments (which would break the comment).</p>
  
  <p>I have tried this (a range expression) to no avail:</p>
  
  <pre><code>sed -e '/\/*/,/*\//! s_//\(.*\)_/*\1 */_' &gt; filename
  </code></pre>
  
  <p>Will something work to ignore the 1 line comments inside a comment like this but change everything else?</p>
  
  <pre><code>/**********************************
  * Some comment
  * an example bit of code within the comment followed by a //comment
  * some more comment
  ***********************************/
  y = x+7; //this comment must be changed
  </code></pre>
  
  <p>Thanks!</p>