-1

Is there a way to write a for loop with a URL and change the URL each time? I want to append &skip=XX with different numbers to skip, is there a way to write it so that the variable is in the URL?

closed as unclear what you're asking by slm Jul 3 '14 at 15:24

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    give us your input and wanted output – Networker Jul 3 '14 at 13:08
  • I still dont know too much about cURL coding, but if my url is api.fda.gov/drug/… is there a way to loop it so that I can get a bunch of data from a loop rather than manually? – cbruno Jul 3 '14 at 13:11
  • 4
    Welcome to Unix & Linux! Please edit your question to add extra information, it is hard to read and easy to miss in the comments. Anyway, what you're asking for is trivial but to help you we need specific examples since the details depend on the URL format. – terdon Jul 3 '14 at 13:21
  • @terdon I think I figured most of it out using the command prompt (I am working from Win 7): FOR /L %i IN (0,100,500) DO echo curl "api.fda.gov/drug/event.json?&search=receivedate:[20040101+TO+20150101]&limit=100&skip=%i" Right now that will echo the 5 different url's, but I am having trouble with curl (6) errors telling me that they cannot resolve the host. Any idea on how to get past it? I've tried everything I found on forums. – cbruno Jul 7 '14 at 19:25
  • Sorry but this site is about Linux and Unix systems, Windows questions are very much off topic here. – terdon Jul 7 '14 at 21:00
5

Yes, easily. For example:

for num in 100 200 300; do curl "http://foo.bar&skip=$num" ; done

Or, you can have the list of numbers in a file (one per line) and use a while loop:

while read num;  do curl "http://foo.bar&skip=$num" ; done < nums.txt

Or even generate them using seq:

seq 100 100 300 | while read num;  do curl "http://foo.bar&skip=$num" ; done

Not the answer you're looking for? Browse other questions tagged or ask your own question.