Linux Shell脚本从网页中提取文本并修剪

Linux Shell脚本从网页中提取文本并修剪,linux,shell,webpage,pull,Linux,Shell,Webpage,Pull,我不知道如何诚实地修剪文字 到目前为止,我所拥有的: wget --output-document=- http://www.geupdate.com 2>/dev/null \ | grep last \ 产出: <li><b><img src='http://www.geupdate.com/img/arrow-tail.png' align='left'>Time since last update</b>: <br />

我不知道如何诚实地修剪文字

到目前为止,我所拥有的:

wget --output-document=- http://www.geupdate.com 2>/dev/null \
| grep last \
产出:

<li><b><img src='http://www.geupdate.com/img/arrow-tail.png' align='left'>Time since last update</b>: <br />0 day, 19 hours, 23 min, 36 sec</li><li><b><img src='http://www.geupdate.com/img/ledlightblue.png' align='left'>An Update to occur within:</b> (<a href='http://www.geupdate.com/update-prediction/'><font size='-2'>?</font></a>) <br />0 day, 21 hours, 56 min, 30 sec</li>               </ul>
如果有人能告诉我如何写一些东西,或者写得这么简单,那就太好了

当我运行此命令时:

wget --output-document=- http://www.geupdate.com 2>/dev/null \
| grep last \
| grep -o '[[:digit:]]* day.* sec'
我明白了:

0 day, 19 hours, 43 min, 16 sec</li><li><b><img src='http://www.geupdate.com/img/ledlightblue.png' align='left'>An Update to occur within:</b> (<a href='http://www.geupdate.com/update-prediction/'><font size='-2'>?</font></a>) <br />0 day, 21 hours, 36 min, 50 sec
0天19小时43分钟16秒
  • 将在以下时间内进行更新:()
    0天21小时36分钟50秒
  • 那我怎么能在“秒”之后切断一切呢?@Aaron:那确实切断了
    秒之后的一切。
    grep
    -o
    标志告诉它只生成与模式匹配的子字符串,而不是拉动包含它的整行。(“O”代表“only”。虽然助记符只解释了它的一半行为:
    echo 1234 | grep-O'[1234]
    将在单独的行上打印
    1
    2
    3
    、和
    4
    ,但从名称“only”来看并不明显。)我更新了我的原始帖子,以显示我运行您建议的内容时得到的结果@亚伦:哦,对不起,我没有注意到有两个独立的“日、时、分、秒”公式。我修改了我的答案,给出了一个更严格的匹配,一次只能捕获一个实例,并添加了一个
    |head-1
    来抑制除第一个实例以外的所有实例。Re:如何知道这些东西:我不知道。随着时间的推移,我慢慢地遇到了这些实用程序。我不知道有什么好的资源可以引导你浏览所有有用的资源。我想这是个好的开始。Re:要捕获第n个实例:您可以(例如)执行
    |head-5|tail-1
    来获取第五个实例,而不是
    |head-1
    head-5
    输出其输入的前五行,而
    tail-1
    输出其输入的最后一行,因此
    head-5 | tail-1
    输出其输入的第五行。
    0 day, 19 hours, 43 min, 16 sec</li><li><b><img src='http://www.geupdate.com/img/ledlightblue.png' align='left'>An Update to occur within:</b> (<a href='http://www.geupdate.com/update-prediction/'><font size='-2'>?</font></a>) <br />0 day, 21 hours, 36 min, 50 sec
    
    wget --output-document=- http://www.geupdate.com 2>/dev/null \
    | grep last \
    | grep -o '[[:digit:]]* days*, [[:digit:]]* hours*, [[:digit:]]* min, [[:digit:]]* sec' \
    | head -1