Shell Scripting – Download and Rename Links from .txt File

catdownloadrenamewgetxargs

Let's say I have a .txt file where I have a list of image links that I want to download. example:

image.jpg
image2.jpg
image3.jpg

I use: cat images.txt | xargs wget
and it works just fine

What I want to do now is to provide another .txt file with the following format:

some_id1 image.jpg
some_id2 image2.jpg
some_id3 image3.jpg

What I want to do is to split each line in the ' ' , download the link to the right, and change the downloaded file-name with the id provided to the left.

I want to somehow use wget image.jpg -O some_id1.jpg for each separate line.

So the output will be:

some_id1.jpg
some_id2.jpg
some_id3.jpg

Any ideas ?

Best Answer

This might do your job,

while read a b
 do
    wget "$b" -O "$a".jpg
    printf "$a".jpg"\n%s" >> newfile
done  < images.txt
Related Question