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

时间:2011-11-27 02:06:58

标签: 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 />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>

我真正想要删除的是:

0 day, 19 hours, 23 min, 36 sec

如果有人可以告诉我怎么写东西或写它如果那么简单,那就太好了!

当我运行时:

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

1 个答案:

答案 0 :(得分:3)

wget --output-document=- http://www.geupdate.com 2>/dev/null \
| grep last \
| grep -o '[[:digit:]]* days*, [[:digit:]]* hours*, [[:digit:]]* min, [[:digit:]]* sec' \
| head -1