0

I have a html table from which I want to remove rows with a certain class. However: When I try sed 's/<tr class="expandable">.*<\/tr>//g it just does nothing (say: does not remove the tag)

An example input could be:

<tr><td>Some col</td></tr>
<tr class="expandable">
    <td colspan="6">
        <div class="expandable-content">
<p>Holds ACCA Practising Certificate: This indicates a member holding a practising certificate issued by ACCA. This means that the member is authorised to provide a range of general accountancy services to individuals and businesses, including business and tax advice and planning, preparation of personal and business tax returns, set up of book-keeping and business systems, providing book-keeping services, payroll work, assistance with management accounting help with raising finance, budgeting and cash-flow advice, business start-up advice and expert witness.</p>
        </div>
    </td>
</tr>

I am not a sed pro and appreciate any help you can give me!

Fuzzyma
  • 7,619
  • 6
  • 28
  • 60
  • 3
    The obligatory [don't parse HTML with regex](http://stackoverflow.com/a/1732454/7552) link. – glenn jackman Sep 28 '16 at 13:50
  • "Have you tried using an XML parser instead?" -> xmllint and xidel which both cant remove a certain row "type" - at least I dont know a way – Fuzzyma Sep 28 '16 at 13:52
  • I think there is a typo in sample input shown, last line probably is `` ... this might work `perl -0777 -pe 's|.*?||gs' file` but not robust as has been pointed out – Sundeep Sep 28 '16 at 14:21

1 Answers1

2

Assuming your html is valid XML, you can use a tool like :

xmlstarlet ed -d '//tr[@class="expandable"]' <<ENDHTML
<html><body><table>
  <tr><td>Some col</td></tr>
  <tr class="expandable">
      <td colspan="6">
          <div class="expandable-content">
  <p>Holds ACCA Practising Certificate: This indicates a member holding a practising certificate issued by ACCA. This means that the member is authorised to provide a range of general accountancy services to individuals and businesses, including business and tax advice and planning, preparation of personal and business tax returns, set up of book-keeping and business systems, providing book-keeping services, payroll work, assistance with management accounting help with raising finance, budgeting and cash-flow advice, business start-up advice and expert witness.</p>
          </div>
      </td>
  </tr>
</table></body></html>
ENDHTML
<?xml version="1.0"?>
<html>
  <body>
    <table>
      <tr>
        <td>Some col</td>
      </tr>
    </table>
  </body>
</html>
glenn jackman
  • 238,783
  • 38
  • 220
  • 352