Search code examples
regexbashcurlgrep

Capture the progress percentage of curl but without the decimal numbers


This question is particularly a regular expression issue.

I'd like to capture the progress percentage of curl command in bash using grep, but excluding the floating point numbers. The goal is to present these captured values to a dialog's --gauge option.

Here's what I've achieved so far:

$ curl -#LO "http://upload.wikimedia.org/wikipedia/commons/4/4e/Pleiades_large.jpg" 2>&1 | stdbuf -oL tr '\r' '\n' | grep -Eo '[0-9.]*'

The above example command will output something like this:

3.8
20.1
47.1
93.4
100.0

But I'm expecting results like this:

3
20
47
93
100

I've searched for a regex to this, but I didn't find any good results.

Any help is greatly appreciated.


Solution

  • Just cut your output using . as separator

    $ curl -#LO "http://upload.wikimedia.org/wikipedia/commons/4/4e/Pleiades_large.jpg" 2>&1 | stdbuf -oL tr '\r' '\n' | grep -Eo '[0-9.]*' | cut -f1 -d\.