fragant
fragant

Reputation: 362

How to pass a URL to Wget

If I have a document with many links and I want to download especially one picture with the name www.website.de/picture/example_2015-06-15.jpeg, how can I write a command that downloads me automatically exactly this one I extracted out of my document?

My idea would be this, but I'll get a failure message like "wget: URL is missing":

grep -E 'www.website.de/picture/example_2015-06-15.jpeg' document | wget

Upvotes: 11

Views: 6346

Answers (3)

Marc B
Marc B

Reputation: 360672

Use xargs:

grep etc... | xargs wget

It takes its stdin (grep's output), and passes that text as command line arguments to whatever application you tell it to.

For example,

echo hello | xargs echo 'from xargs '

produces:

from xargs  hello

Upvotes: 13

Jahid
Jahid

Reputation: 22428

This will do too:

wget "$(grep -E 'www.website.de/picture/example_2015-06-15.jpeg' document)"

Upvotes: 2

r3mainer
r3mainer

Reputation: 24557

Using back ticks would be the easiest way of doing it:

wget `grep -E 'www.website.de/picture/example_2015-06-15.jpeg' document`

Upvotes: 5

Related Questions