Amateur Math Guy
Amateur Math Guy

Reputation: 199

Using Curl To Download Files

I am currently trying to learn how to use the curl command to download some data and have run into some difficulty. So I have a list of stock symbols (eg AAPL, GOOG, TGT, ...) and I want to use this link (http://ichart.finance.yahoo.com/table.csv?s=YHOO&d=0&e=28&f=2010&g=d&a=3&b=12&c=1996&ignore=.csv) to download the data I need into a csv file. I got the idea from another stackoverflow questions top answer (source of historical stock data).

So here is my attempt

$ for i in $(cat ticker.txt); do curl -o $i.csv http://ichart.finance.yahoo.com
/table.csv?s=$i&d=0&e=28&f=2010&g=d&a=3&b=12&c=1996&ignore=.csv; done

So I have a text file with all of the tickers I'm interested in and this downloads some files, but then the process seems to hang up and just stops at the end. Also, the correct information doesn't seem to be downloaded (ie instead of getting data from 2010 to 1996 I get all available data starting from 2014 to some random year).

I am using Git Bash because I'm running Windows 7 and don't have a UNIX style OS to practice these different commands with. Can someone out there help me with this issue and maybe point out what I'm doing wrong?

Upvotes: 2

Views: 1956

Answers (1)

MLSC
MLSC

Reputation: 5972

You should quote the URL:

for i in $(cat ticker.txt); do curl -o $i.csv "http://ichart.finance.yahoo.com
/table.csv?s=$i&d=0&e=28&f=2010&g=d&a=3&b=12&c=1996&ignore=.csv"; done

I don't know the length of URL in this thread

Upvotes: 1

Related Questions