Kristian Kristian - 6 months ago 22
Linux Question

wget multiple files with numeric patterns

I'd like to

wget
several files, with an incrementing
YEAR
param.

the list of files would be something like this:

http://example.com/2000/Q1/file.txt
http://example.com/2001/Q1/file.txt
http://example.com/2002/Q1/file.txt
http://example.com/2003/Q1/file.txt


And I would like to also increment an
-O
output file name option too.

wget -O file.{2000..2003}.Q1.txt http://example.com/{2000..2003}/Q1/file.txt


So that way I'd end up with this:

file.2000.Q1.txt
file.2001.Q1.txt
file.2002.Q1.txt
file.2003.Q1.txt


I tried a couple variants of that, and I get minor errors and the output file names seem to not increment. How can I get the desired file output names?

Answer

To use the same value at multiple places, you need to have the value in a variable, in a loop, for example:

for year in {2000..2003}; do
     echo wget http://example.com/$year/Q1/file.txt -O file.$year.Q1.txt
done
Comments