html - 如何在bash中仅使用grep提取html标签

标签 html linux bash tags grep

所以我有这个代码

<span class="cur_wind">Sunrise <b>7:33 a.m.</b> <br />

我想使用 grep 来提取其中的日出时间和日落时间。我该怎么做?我只想使用 grep,因为我不熟悉 awk 和 sed 等。干杯!

最佳答案

确实不是这里的方法,但是如果您没有任何额外的时间运算符,像下面这样的原始方法可能会起作用。

grep -oP "(Sunrise|Sunset|\d+:\d+ (a.m|p.m))" 

示例输出

> cat file
<td valign="top"><span class="cur_wind">Sunrise <b>7:33 a.m.</b> <br />
            Sunset&nbsp; <b>7:17 p.m.</b></span></td>
> grep -oP "(Sunrise|Sunset|\d+:\d+ (a.m|p.m))" file 
Sunrise
7:33 a.m
Sunset
7:17 p.m

或者,像这样的事情可能会消除更多错误情况

grep -oP "(Sunrise(.*)\d+:\d+ (a.m|p.m))|(Sunset(.*)\d+:\d+ (a.m|p.m))" file 
Sunrise <b>7:33 a.m
Sunset&nbsp; <b>7:17 p.m

您可以通过管道发送到 再次删除标签字符。

关于html - 如何在bash中仅使用grep提取html标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22741358/

相关文章:

Python Scapy nfqueue

linux - WebDriver异常: no chrome binary at/usr/bin/google-chrome-stable or chrome binary not found

linux - 有什么方法可以将/dev/urandom 生成的字符流拆分成不同的子流吗?

bash - 在特定位置合并两个文本文件,sed 或 awk

html - 网络聊天的 CSS 布局不起作用

javascript - 任何人都可以建议在模式打开时在 Firefox 中使用箭头键滚动页面的解决方案吗?

jquery - 如何在提交时调用函数?

css - 推荐的边距或填充是什么?

java - 从 Linux 到 2012r2 Active Directory 的 LDAPS Java 查询的最低要求是什么

perl - 如何在 perl 中禁用 stdout 重定向到文件缓冲?