Skip to content
Advertisement

How can I show the wget progress bar only? [closed]

For example:

wget http://somesite.com/TheFile.jpeg

    downloading: TheFile.tar.gz ...
    --09:30:42--  http://somesite.com/TheFile.jpeg
               => `/home/me/Downloads/TheFile.jpeg'
    Resolving somesite.co... xxx.xxx.xxx.xxx.
    Connecting to somesite.co|xxx.xxx.xxx.xxx|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 1,614,820 (1.5M) [image/jpeg]

    25% [======>                              ] 614,424      173.62K/s    ETA 00:14

How can I get it to look like the following?

    downloading: TheFile.jpeg ...
    25% [======>                              ] 614,424      173.62K/s    ETA 00:14

I know curl can do that. However, I need to get wget to do that job.

Advertisement

Answer

You can use the following filter:

progressfilt ()
{
    local flag=false c count cr=$'r' nl=$'n'
    while IFS='' read -d '' -rn 1 c
    do
        if $flag
        then
            printf '%s' "$c"
        else
            if [[ $c != $cr && $c != $nl ]]
            then
                count=0
            else
                ((count++))
                if ((count > 1))
                then
                    flag=true
                fi
            fi
        fi
    done
}

Usage:

$ wget --progress=bar:force http://somesite.com/TheFile.jpeg 2>&1 | progressfilt
100%[======================================>] 15,790      48.8K/s   in 0.3s

2011-01-13 22:09:59 (48.8 KB/s) - 'TheFile.jpeg' saved [15790/15790]

This function depends on a sequence of 0x0d0x0a0x0d0x0a0x0d being sent right before the progress bar is started. This behavior may be implementation dependent.

Advertisement