用sed提取HTML标签数据 [英] Extract HTML tag data with sed
问题描述
我希望在已知的HTML标签之间提取数据。例如:
您好,< i> I< i>非常< i>< / i>很高兴见到你。
应该变成:
'I
非常'
所以我发现了一些可以用于几乎的事情。不幸的是,它只提取最后一个条目。
sed -n -e's /.*& lt; i> \(。* \\ \\)现在我可以追加任何结束标记<$ c
$ c>< / i> 换行符,这很好。但是有没有一种方法可以用一个sed命令来完成呢?
试试这个:
sed -n's | [^<] *< i> \([^<] * \)< / i> ; [^<] * | \1\\\
| gp'
你的例子是缺少/:
您好,< i> I< / i>非常< i>< / i>很高兴认识你。
I wish to extract data between known HTML tags. For example:
Hello, <i>I<i> am <i>very</i> glad to meet you.
Should become:
'I
very'
So I have found something that works to nearly do this. Unfortunately, it only extracts the last entry.
sed -n -e 's/.*<i>\(.*\)<\/i>.*/\1/p'
Now I can append any end tag </i>
with a newline character and this works fine. But is there a way to do it with just one sed command?
Give this a try:
sed -n 's|[^<]*<i>\([^<]*\)</i>[^<]*|\1\n|gp'
And your example is missing a "/":
Hello, <i>I</i> am <i>very</i> glad to meet you.
这篇关于用sed提取HTML标签数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!