FurtiveFelon
FurtiveFelon

Reputation: 15186

how to download files within a range with curl, and assign custom file names?

So I'm attempting to download a bunch of files with the following command:

curl -O http://example.com/[1-100]/test.json

It would save all the files as test.json, is there any way of specifying a dynamic filename for each file in the range?

Thanks!

Jason

Upvotes: 3

Views: 4150

Answers (2)

Yaroslav
Yaroslav

Reputation: 2438

According to docs: https://curl.haxx.se/docs/manpage.html

-o, --output

Write output to instead of stdout. If you are using {} or [] to fetch multiple documents, you can use '#' followed by a number in the specifier. That variable will be replaced with the current string for the URL being fetched.

so you can combine custom filename for new file using #n placeholder

curl http://example.com/[1-100]/test.json -o response_#1.json

where in #1 curl will place current iterator

Upvotes: 6

bitops
bitops

Reputation: 4292

Try this:

for i in $(seq 1 100)
do
  curl -o "test.$i.json" "http://example.com/$i/test.json"
done

The curl man page is pretty extensive, it has all kinds of options. You can check it out at http://curl.haxx.se/docs/manpage.html

Upvotes: -1

Related Questions