Hello:
I have the following HTML table:
<table>
<thead>
<tr>
<th>Code</th>
<th>Percentage</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>30%</td>
</tr>
<tr>
<td>2</td>
<td>70%</td>
</tr>
</tbody>
</table>
I would like to add a button with an event to every <td>
element with a code, like the following:
<table>
<thead>
<tr>
<th>Code</th>
<th>Percentage</th>
</tr>
</thead>
<tbody>
<tr>
<td><button onclick="reset(1)">Reset</button>1</td>
<td>30%</td>
</tr>
<tr>
<td><button onclick="reset(2)"></button>2</td>
<td>70%</td>
</tr>
</tbody>
</table>
Note that I'm not asking how to parse the HTML. Instead, I would like to know how to replace every \t\t\t<td>x</td>
line by \t\t\t<td><button onclick="reset(x)">x</button></td>
, where x
is the code number.
I need to do it with a command-line text editor without input from the user, because I have many files like this one and my idea is to edit all of them using find
with the -exec
option.
This would be a simple task with ex
or ed
if I just had to replace the same concurrence. But in this case, I need to keep the code in every replacement. That's what I'm struggling with. I'm afraid I'll need advanced tools like awk
and I honestly don't know how to do it.
How can I add the button with the event to the table cells?
Thanks in advance.