title: Manipulate, process HTML from command line
body: <p>I am looking for a way to process a HTML code from command line (probably using XPATH).</p>
  
  <p>For example I want to remove  in <code>.container</code> class or add new <code>&lt;div&gt;</code> after <code>.container</code> class.</p>
  
  <p><strong>Input:</strong></p>
  
  <pre><code>&lt;div class="bg-detail2" id="geometry"&gt;
      &lt;div class="container"&gt;
          &lt;h2&gt;Title&lt;/h2&gt;
          &lt;div class="line"&gt;&lt;/div&gt;
          &lt;div class="fix"&gt;&lt;/div&gt;
          &lt;div class="col50"&gt;
              Content
          &lt;/div&gt;
          &lt;div class="col50"&gt;
              Another Content
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>&lt;div class="bg-detail2" id="geometry"&gt;
      &lt;div class="container"&gt;
        &lt;div class="newdiv&gt;
          &lt;div class="line"&gt;&lt;/div&gt;
          &lt;div class="fix"&gt;&lt;/div&gt;
          &lt;div class="col50"&gt;
              Content
          &lt;/div&gt;
          &lt;div class="col50"&gt;
              Another Content
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>My first idea is to use <code>sed</code>, but it is not a bullet proof method. I know <code>xmllint</code>, but it can only read HTML files.</p>
  
  <p>Is there any other tool available for command line?</p>