如何替换html标签之间的任何文本 [英] How to replace any text between html tags
问题描述
我在html标签之间有文字。例如:
< td> vip< / td>
我会在< td>< / td> ;
如何从这些标签中剪切任何文本并在这些标签之间放置任何文本。
我需要通过bash / shell来完成。
我该怎么做?
首先,我试图得到这个文本,但没有成功
sed -n/< td> /,/< \ / td> / p的test.txt
。但是结果是我有
< td> vip< / td>
。但根据文档,我应该只获得 vip
您可以试试这个:
sed -i -e's / \(< td> \)。* \( < \ / td> \)/< td> TEXT_TO_REPLACE_BY< \ / td> / g'test.txt
请注意,它只适用于< td>
标签。它将用 TEXT_TO_REPLACE_BY
替换标记< td>
(实际上将它们放在一起并将标记放回)之间的所有内容。
i have text between html tags. For example:
<td>vip</td>
I will have any text between tags <td></td>
How can i cut any text from these tags and put any text between these tags.
I need to do it via bash/shell.
How can i do this ?
First of all, i tried to get this text, but without success
sed -n "/<td>/,/<\/td>/p" test.txt
. But in a result i have
<td>vip</td>
. but according to documentation, i should get only vip
You can try this:
sed -i -e 's/\(<td>\).*\(<\/td>\)/<td>TEXT_TO_REPLACE_BY<\/td>/g' test.txt
Note that it will only work for the <td>
tags. It will replace everything between tags <td>
(actually with them together and put the tags back) with TEXT_TO_REPLACE_BY
.
这篇关于如何替换html标签之间的任何文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!