输入:
<tr><td>FOOBAAR</td><td>FOOO</td><td>BAAR</td><td><font style=BACKGROUND-COLOR:red>2014-02-14 13:34</font></td><td><font style=BACKGROUND-COLOR:red>2014-02-17 13:34</font></td><td><font style=BACKGROUND-COLOR:red>2014-03-07 13:34</font></td></tr>
输出:
<tr><td>FOOBAAR</td><td>FOOO</td><td>BAAR</td><td>2014-02-14 13:34</td><td><font style=BACKGROUND-COLOR:red>2014-02-17 13:34</font></td><td><font style=BACKGROUND-COLOR:red>2014-03-07 13:34</font></td></tr>
区别:
<font style=BACKGROUND-COLOR:red>
和
</font>
仅从第四列中删除。
我的问题:如何从给定列中仅删除给定字符串?
</td><td>
是分隔符
我建议使用HTML解析工具,而不要使用正则表达式。(著名的答案解释为什么在这里)
这是使用XML解析器的示例(注意:要求输入格式正确的XML,而示例HTML则不是)
# change the value of the style attribute of the font tag of the 4th td tag
# to the empty string
xmlstarlet ed -O -u '//table/tr/td[4]/font[@style]/@style' -v "" <<END
<html><head></head><body><table>
<tr><td>FOOBAAR</td><td>FOOO</td><td>BAAR</td><td><font style="BACKGROUND-COLOR:red">2014-02-14 13:34</font></td><td><font style="BACKGROUND-COLOR:red">2014-02-17 13:34</font></td><td><font style="BACKGROUND-COLOR:red">2014-03-07 13:34</font></td></tr>
</table></body></html>
END
<html>
<head/>
<body>
<table>
<tr>
<td>FOOBAAR</td>
<td>FOOO</td>
<td>BAAR</td>
<td>
<font style="">2014-02-14 13:34</font>
</td>
<td>
<font style="BACKGROUND-COLOR:red">2014-02-17 13:34</font>
</td>
<td>
<font style="BACKGROUND-COLOR:red">2014-03-07 13:34</font>
</td>
</tr>
</table>
</body>
</html>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句