title: UNIX Sed and inverse string search
body: <p>I have a simple (at least I thought it was) assignment where I have to use sed to replace a string with my username in a file. Lets say that it content looks like this: </p>
  
  <pre><code>1)
  2)
  3)
  3) www
  www 3)
  3)
  7)
  </code></pre>
  
  <p>The assignment has 3 parts:</p>
  
  <p>-replace '3)' with your username. This command works just fine: </p>
  
  <pre><code>  sed -e "s/3)/$USER/" file
  </code></pre>
  
  <p>-replace '3)' with your id only in lines with 'www' string. With minor improvements the command form the first part also gets the job done: </p>
  
  <pre><code>  sed -e "/www/ s/3)/$USER/" file
  </code></pre>
  
  <p>In the last part of the assignment I have to replace 3) with my id only in the lines without 'www'. Is there a simple way to reverse search for a string using sed? so far I've come up with an idea to negate a set of 3 characters inside '[]' but sadly it doesn't really work. </p>
  
  <pre><code>  sed -e "/[^/(www/)]/ s/3)/$USER/" file
  </code></pre>