【问题标题】:i got line from html file using grep in unix script, but i can't figure out how to extract text using sed我在 unix 脚本中使用 grep 从 html 文件中得到了一行,但我不知道如何使用 sed 提取文本
【发布时间】:2014-01-21 17:59:14
【问题描述】:

我正在制作一个 shell 脚本,它显示收音机中播放的歌曲的标题和艺术家。我得到了 html 文件,我使用 grep 找到了我需要的行,但不知道如何提取我需要的文本。 我得到的线是

<div class="n Title">title, different every time </div><div class=n Artist">artist that changes also</div> 

如何使用 unix 命令提取标题和艺术家? 我尝试了很多方法,但都无法正常工作。

【问题讨论】:

    标签: html unix sed grep


    【解决方案1】:
    grep -Po 'Title">\K[^<]*'
    

    给你标题,同样的想法你可以得到艺术家。但请记住,使用正则表达式“解析” xml/html 是有风险的,例如,网站更改了 html 源代码,将其分成几行......或者他们添加了一些其他属性,或者在 @ 之后添加了一些其他 css 类987654322@...

    【讨论】:

    • 非常感谢,这是我的功课,等我学业有进步的时候,我会努力的:)
    猜你喜欢
    • 1970-01-01
    • 2016-04-21
    • 2021-04-18
    • 1970-01-01
    • 1970-01-01
    • 2022-01-12
    • 2017-12-13
    • 1970-01-01
    • 2011-08-14
    相关资源
    最近更新 更多