title: Remove/Add Comment from config file using sed
body: <p>I have a file which contains below data.</p>
  <pre><code>192.168.1.1
  255.255.255.0
  192.168.1.10
  
  192.168.1.2
  255.255.255.0
  192.168.1.10
  
  #192.168.2.1
  #255.255.255.0
  #192.168.2.10
  
  #192.168.2.2
  #255.255.255.0
  #192.168.2.10
  </code></pre>
  <p>Now I want to achieve following</p>
  <ol>
  <li>Remove the # from the beginning of lines which already have it.</li>
  <li>Put the # in the beginning of the lines which doesn't have it.</li>
  </ol>
  <p>The the final file will look like</p>
  <pre><code>#192.168.1.1
  #255.255.255.0
  #192.168.1.10
  
  #192.168.1.2
  #255.255.255.0
  #192.168.1.10
  
  192.168.2.1
  255.255.255.0
  192.168.2.10
  
  192.168.2.2
  255.255.255.0
  192.168.2.10
  </code></pre>
  <p>I was trying to achieve this with sed using below command in my script but it is not working.</p>
  <p>for commenting</p>
  <pre><code>sed -i -e &quot;/192.168.1./{N;N;p;}/s/^#*/#/&quot;
  </code></pre>
  <p>for removing comment</p>
  <pre><code>sed -i -e &quot;/192.168.2./{N;N;p;}/s/^#*//&quot;
  </code></pre>
  <p>but sed throws error below.</p>
  <pre><code>sed: -e expression #1, char 21: extra characters after command
  </code></pre>
  <p>Any suggestion.</p>