是否可以抓取wget的最后一行?
$ wget --output-document=/dev/null http://website.com/file.jpg
Resolving speedtest.sea01.softlayer.com... 67.228.112.250
Connecting to speedtest.sea01.softlayer.com|67.228.112.250|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1986284 (1.9M) [image/jpeg]
Saving to: `/dev/null'
2011-10-02 22:38:04 (337 KB/s) - `/dev/null' saved [1986284/1986284]
上面一切正常,但我想知道如何将最后一行存储在变量中或通过 GREP -> 传递它/((.+))/
(我正在尝试解析平均 KB/s)
$ wget --output-document=/dev/null http://website.com/file.jpg
Resolving speedtest.sea01.softlayer.com... 67.228.112.250
Connecting to speedtest.sea01.softlayer.com|67.228.112.250|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1986284 (1.9M) [image/jpeg]
Saving to: `/dev/null'
2011-10-02 22:38:04 (337 KB/s) - `/dev/null' saved [1986284/1986284]
Everything works above, but I would like to know how to store the last line in a variable OR pass it through GREP -> /((.+))/
(I'm trying to parse for the average KB/s)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以重定向命令的输出。例如:
You can redirect the output of the command. For example:
如果您安装了 apache,则可以使用 Apache HTTP 服务器基准测试工具:
您会得到如下输出:
If you have apache installed, you can use Apache HTTP server benchmarking tool:
you get output like:
在我的系统上,最终的输出行是空的,否则 sed 寻址会更简单。这是在 Ubuntu 上开箱即用的;如果您的
sed
不同,您可能需要稍微调整脚本。(我首先尝试使用
grep -o '(.*)'
,但在wget
的输出中前面的括号中还有其他文本。)On my system, the final output line is empty, otherwise the
sed
addressing would be simpler. This is on Ubuntu out of the box; if yoursed
is different, you may need to adapt the script slightly.(I tried with
grep -o '(.*)'
at first, but there is other text in parentheses earlier in the output fromwget
.)