How to pass a URL to Wget

5.7k Views Asked by At

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
3

There are 3 best solutions below

0
On BEST ANSWER

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

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

This will do too:

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

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