Wget: read url from file, add number sequence to url
I am reading a file (with urls) line by line:
#!/bin/bash
while read line
do
url=$line
wget $url
wget $url_{001..005}.jpg
done < $1
First, I want to download the main url as you can see wget $url
. Then I want to add to the serial numbers of the URLs (_001.jpg, _002.jpg, _003.jpg, _004.jpg, _005.jpg):
wget $url_{001..005}.jpg
... but for some reason it doesn't work.
Sorry missed one thing: the url is similar to http://xy.com/052914.jpg
. Is there an easy way to add _001 before the extension? http://xy.com/052914_001.jpg
... Or do I have to remove the ".jpg" from the file containing the url and then just add it later to the variable?
source to share
Try encapsulating the variable name:
wget ${url}_{001..005}.jpg
Bash is trying to expand a variable $url_
in your command.
As for your jpg within the following url, see the substring expansion in the Bash manual .
wget ${url:0: -4}_{001..005}.jpg
:0: -4
means it will move to the variable from the zero position (first character), minus the last 4 characters.
Or from this answer :
wget ${url%.jpg}_{001..005}.jpg
%.jpg
specifically removes .jpg
and will work in older versions bash
.
source to share