我想wget
多个文件,并且递增YEAR
个参数。
文件列表将是这样的:
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
我还希望增加-O
输出文件名选项。
wget -O file.{2000..2003}.Q1.txt http://example.com/{2000..2003}/Q1/file.txt
这样我最终会得到这个:
file.2000.Q1.txt
file.2001.Q1.txt
file.2002.Q1.txt
file.2003.Q1.txt
我尝试了几种变体,我得到了小错误,输出文件名似乎没有增加。如何获取所需的文件输出名称?
答案 0 :(得分:2)
要在多个位置使用相同的值,您需要在循环中将值保存在变量中,例如:
for year in {2000..2003}; do
echo wget http://example.com/$year/Q1/file.txt -O file.$year.Q1.txt
done
答案 1 :(得分:1)
您可以使用多个wget
命令:
for y in $(seq 2000 2003); do
wget http://example.com/$y/Q1/file.txt -O file.$y.Q1.txt
done