linux - 使用 sed 在 Bash 中解析 HTML 表

标签 linux bash sed

在 bash 中我试图解析以下文件:

输入:

</a></td></tr><tr><td>stuff.txt (15.18 KB)</td><td>12/01/2015</td><td>Large things</td><td>158520312</td><td><a class="btn-down" download href="https://resource.com/stones">
</a></td></tr><tr><td>flowers.pdf (83.03 MB)</td><td>23/03/2011</td><td>Large flowers</td><td>872448000</td><td><a class="btn-down" download href="https://resource.com/flosers with stuff">
</a></td></tr><tr><td>apples.pdf (281.16 MB)</td><td>21/04/2012</td><td>Large things like apples</td><td>299009564</td><td><a class="btn-down" download href="https://resource.com/apples">
</a></td></tr><tr><td>stones.pdf (634.99 MB)</td><td>11/07/2011</td><td>Large stones from mountains</td><td>67100270</td><td><a class="btn-down" download href="https://stuff.com/findstones">

想要的输出:

12/01/2015 158520312 "https://resource.com/stones"
23/03/2011 872448000 "https://resource.com/flosers with stuff"
21/04/2012 299009564 "https://resource.com/apples~withstuff"
11/07/2011 67100270 "https://stuff.com/findstones"

我想说的是:

# less input.txt | sed -e "s/><tr><td//" -e "s/\///" -e "s/a>//" -e "s/<\/td><\/tr>//g" -e "s/<\/td><td>//g" -e "s/>$//g" -e "s/<a class=\"btn-down\" download href=//g"

<stuff.txt (15.18 KB)12/01/2015Large things158520312"https://resource.com/stones"
<flowers.pdf (83.03 MB)23/03/2011Large flowers872448000"https://resource.com/flosers with stuff"
<apples.pdf (281.16 MB)21/04/2012Large things like apples299009564"https://resource.com/apples"
<stones.pdf (634.99 MB)11/07/2011Large stones from mountains67100270"https://stuff.com/findstones"

有没有更简单的方法来解析它?我觉得它可以做得更简单,而且我什至没有进行解析。

最佳答案

您可以尝试关注并告诉我们这是否对您有帮助。

awk -F"[><]" '{sub(/.*=/,"",$28);print $15,$23,$28}'  Input_file

关于linux - 使用 sed 在 Bash 中解析 HTML 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50991066/

相关文章:

linux - 如何在不创建新文件的情况下合并大量文件

linux - 从 VPS 备份所有网页文件

csv - 使用 Sed、Awk 等将第一列中每一行的数据复制到最后一列中的 html 超链接中

linux - 如果 tar 被中断,它会覆盖它操作的第一个文件。有什么办法可以防止这种情况发生吗?

linux - 如何可靠地跟踪 POSIX 系统上的子/孙进程?

c - fopen、fprintf、fclose 的单行代码?

linux - 将及时命令传送到 ssh

macos - 将命令的输出解析为变量 LIVE(网络流量监控)

ANT 中的 Bash 脚本用于删除文件中的文本

linux - SVN 连接被拒绝