gpt4 book ai didi

linux - 在 HTML 标签中匹配模式和替换

转载 作者:太空宇宙 更新时间:2023-11-04 10:31:36 25 4
gpt4 key购买 nike

    </tr>
<tr class='htmllist_tr' style="background-color:yellow" ><td class='htmllist_td' >INDX01</td>
<td class='htmllist_td_nbr' >964.87</td>
<td class='htmllist_td_nbr' >95.13</td>
<td class='htmllist_td' >NehaA9.86</td>
</tr>
<tr class='htmllist_tr' ><td class='htmllist_td' >UNDOTBS1</td>
<td class='htmllist_td_nbr' >156.25</td>
<td class='htmllist_td_nbr' >8</td>
<td class='htmllist_td' >NehaA5.12</td>
</tr>

想在<tr>之间找到NehaA和 </tr>标签然后改变

`<tr class='htmllist_tr'>` 

<tr class='htmllist_tr' style="background-color:yellow"> 

`<tr class='htmllist_tr' style="background-color:red">` *

试过了

sed -e "/NehaA/ s/\'<tr class='htmllist_tr'>\'/\'<tr class='htmllist_tr' style="background-color:red">\'/ ;" 2932_TABLE2.txt

没有成功请帮忙

最佳答案

如果您使用 HTML 解析器没有得到可用的答案,那么试试这个:

$ awk -v RS='</tr>\\s*' '/Neha/{ORS=RT; sub(/<tr[^>]+>/,""); print "<tr class=\047htmllist_tr\047 style=\"background-color:red\">" $0}' file
<tr class='htmllist_tr' style="background-color:red"><td class='htmllist_td' >INDX01</td>
<td class='htmllist_td_nbr' >964.87</td>
<td class='htmllist_td_nbr' >95.13</td>
<td class='htmllist_td' >NehaA9.86</td>
</tr>
<tr class='htmllist_tr' style="background-color:red"><td class='htmllist_td' >UNDOTBS1</td>
<td class='htmllist_td_nbr' >156.25</td>
<td class='htmllist_td_nbr' >8</td>
<td class='htmllist_td' >NehaA5.12</td>
</tr>

它使用 GNU awk 进行多字符 RS 和 RT。

关于linux - 在 HTML 标签中匹配模式和替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39604374/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com