How is grep loading speed with wget output?

I need to upload multiple files with wgetand measure the download speed.

eg. I load using

wget -O /dev/null http://ftp.bit.nl/pub/OpenBSD/4.7/i386/floppy47.fs http://ftp.bit.nl/pub/OpenBSD/4.7/i386/floppyB47.fs

and the way out is

--2010-10-11 18:56:00--  http://ftp.bit.nl/pub/OpenBSD/4.7/i386/floppy47.fs
Resolving ftp.bit.nl... 213.136.12.213, 2001:7b8:3:37:20e:cff:fe4d:69ac
Connecting to ftp.bit.nl|213.136.12.213|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1474560 (1.4M) [text/plain]
Saving to: `/dev/null'

100%[==============================================================>] 1,474,560    481K/s   in 3.0s

2010-10-11 18:56:03 (481 KB/s) - `/dev/null' saved [1474560/1474560]

--2010-10-11 18:56:03--  http://ftp.bit.nl/pub/OpenBSD/4.7/i386/floppyB47.fs
Reusing existing connection to ftp.bit.nl:80.
HTTP request sent, awaiting response... 200 OK
Length: 1474560 (1.4M) [text/plain]
Saving to: `/dev/null'

100%[==============================================================>] 1,474,560    499K/s   in 2.9s

2010-10-11 18:56:06 (499 KB/s) - `/dev/null' saved [1474560/1474560]

FINISHED --2010-10-11 18:56:06--
Downloaded: 2 files, 2.8M in 5.9s (490 KB/s)

I need grep overall download speed, i.e. a string 490 KB/s. How to do it?

PS You may need to consider the case that we will upload only one file, so the final output will not start with FINISHED

+5
source share
5 answers

Update, grep style version using sed:

wget ... 2>&1 | sed -n '$,$s/.*(\(.*\)).*/\1/p'

Old version:

I thought it was easier to split the file size by the download time after download .; -)

(/usr/bin/time -p wget ... 2>&1 >/dev/null; ls -l newfile) | \
awk '
   NR==1 {t=$2};
   NR==4 {printf("rate=%f bytes/second\n", $5/t)}
'

awk "real xx.xx" variabe t. awk ( 5 ls -l) .

+4

, wget -O /dev/null <resource>

\([0-9.]\+ [KM]B/s\)

stderr stdout, :

wget -O /dev/null http://example.com/index.html 2>&1 | grep '\([0-9.]\+ [KM]B/s\)'

, 923 KB/s 1.4 MB/s


grep . (), sed :

wget -O /dev/null http://example.com/index.html 2>&1 |
    sed -e 's|^.*(\([0-9.]\+ [KM]B/s\)).*$|\1|'
+1

, 1 .

sed, wget, , , grep.

:

wget ... 2>&1 | grep -o "[0-9.]\+ [KM]*B/s"

-o , . 1 , . K M B/s

423 KB/s ().

grep , grep -o "[KM]*B/s" grep -o "[0123456789]\+.

+1

:

perl -ne "/^Downloaded.*?\((.*?)\)/; print $1"
-1

. wget's --limit-rate=amount. ,

--limit-rate=400k 400 /. . , .

-3

All Articles