CURL进度条:如何只使用grep管道和提取数字? [英] CURL Progress Bar: How to pipe and extract numbers only using grep?

查看:530
本文介绍了CURL进度条:如何只使用grep管道和提取数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我到目前为止:

  [my1 @ graf home] $ curl  - #-o f1.flv 'http://osr.com/f1.flv'| grep -o'* [0-9] *'
################################## ############################################ 100.0%



我希望使用grep,只提取CURL输出的进度条中的百分比。



我认为我的正则表达式是不正确的,我也不知道这个grep将生效的百分比是不断更新吗?



我想做的是基本上得到CURL只给我百分比数作为输出,没有别的。



谢谢任何帮助。

解决方案

你不能通过grep获得类似的进度信息;



curl 将进度条写入stderr,因此必须重定向到stdout之前你可以grep它:



$ curl - #-o f1.flv'http://osr.com/f1.flv'2> ;& 1 | grep 1 | 结果:

 
^ M 0.0
%^ M ####### ################################################## ############### 100.
0%^ M ######################### ############################################## 100
.0%^ M ################################################## ############################# 10
0.0%

你期望一个连续的数字流,你要重定向到别的地方吗?



如果是前者,这种半分类在一个小文件中工作:

  $ curl  - #-o f1.flv'http://osr.com/f1.flv'2>& 1 | sed's /#// g' -  
100.0%0.0%

在一个大文件。输出不会打印,直到下载完成,可能是因为curl似乎正在发送^ H到终端。可能有一个更好的方法 sed ,但我不会喘口气。

  $ curl  - #-o l.tbz'ftp://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/2009/06/2009-06-02-05-mozilla- 1.9.1 / firefox-3.5pre.en-US.linux-x86_64.tar.bz2'2& 1 | sed's /#// g' -  
100.0 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%% ...


This is what I have so far:

[my1@graf home]$ curl -# -o f1.flv 'http://osr.com/f1.flv' |  grep -o '*[0-9]*'
####################################################################### 100.0%

I wish to use grep and only extract the percentage from that progress bar that CURL outputs.

I think my regex is not correct and I am also not sure if this grep will take effect of the the percentage being continuously updated?

What I am trying to do is basically get CURL only to give me the percentage number as the output and nothing else.

Thank you for any help.

解决方案

You can't get the progress info like that through grep; it doesn't make sense.

curl writes the progress bar to stderr, so you have to redirect to stdout before you can grep it:

$ curl -# -o f1.flv 'http://osr.com/f1.flv' 2>&1 | grep 1 | less results in:

^M                                                                           0.0
%^M######################################################################## 100.
0%^M######################################################################## 100
.0%^M######################################################################## 10
0.0%

Are you expecting a continual stream of numbers that you are redirecting somewhere else? Or do you expect to grab the numbers at a single point?

If it's the former, this sort of half-assedly works on a small file:

$ curl -# -o f1.flv 'http://osr.com/f1.flv' 2>&1 | sed  's/#//g' -
 100.0%                                                                    0.0%

But it's useless on a large file. The output doesn't print until the download is finished, probably because curl seems to be sending ^H's to the terminal. There might be a better way to sed it, but I wouldn't hold my breath.

$ curl -# -o l.tbz 'ftp://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/2009/06/2009-06-02-05-mozilla-1.9.1/firefox-3.5pre.en-US.linux-x86_64.tar.bz2' 2>&1 | sed 's/#//g' -
 100.0%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

这篇关于CURL进度条:如何只使用grep管道和提取数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆