更新时间:2023-02-19 17:07:51
您可以试试这个:
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
.