Issue
I have a table.html file which contains a large table with a lot of inline style
The file is formatted that a tableData tag is in one line. Here is a short example:
<table>
<tbody>
<tr style="height: 17px;">
<td style="width: 120.078px; height: 17px;" align="RIGHT" valign="TOP"><span style="font-size: 10pt; font-family: verdana, geneva, sans-serif;"><strong>CEO </strong></span></td>
<td style="width: 438.922px; height: 49px;" rowspan="2" align="LEFT" valign="TOP"><span style="font-size: 10pt; font-family: verdana, geneva, sans-serif;"><strong> Name<br/></strong> E-Mail<br/></span></td>
</tr>
<tr style="height: 32px;">
<td style="width: 120.078px; height: 32px;" align="RIGHT" valign="TOP"><span style="font-family: verdana, geneva, sans-serif; font-size: 10pt;"> </span></td>
</tr>
</tbody>
The file is huge and I want to delete every line that is a <td> </td>
line and has no content (whitepaces counts also as no content)
I tried to use awk but my knowledge is not enough In this short example the output after the delete would look like this:
<table>
<tbody>
<tr style="height: 17px;">
<td style="width: 120.078px; height: 17px;" align="RIGHT" valign="TOP"><span style="font-size: 10pt; font-family: verdana, geneva, sans-serif;"><strong>CEO </strong></span></td>
<td style="width: 438.922px; height: 49px;" rowspan="2" align="LEFT" valign="TOP"><span style="font-size: 10pt; font-family: verdana, geneva, sans-serif;"><strong> Name<br/></strong> E-Mail<br/></span></td>
</tr>
<tr style="height: 32px;">
</tr>
</tbody>
Solution
Using sed
$ sed -E '/\<td\>/{\~(<[^>]*>)+ *[[:alpha:]] *~!d}' input_file
<table>
<tbody>
<tr style="height: 17px;">
<td style="width: 120.078px; height: 17px;" align="RIGHT" valign="TOP"><span style="font-size: 10pt; font-family: verdana, geneva, sans-serif;"><strong>CEO </strong></span></td>
<td style="width: 438.922px; height: 49px;" rowspan="2" align="LEFT" valign="TOP"><span style="font-size: 10pt; font-family: verdana, geneva, sans-serif;"><strong> Name<br/></strong> E-Mail<br/></span></td>
</tr>
<tr style="height: 32px;">
</tr>
</tbody>
Answered By - HatLess Answer Checked By - Robin (WPSolving Admin)