The problem is, that while the url would suggest it is a CSV, it really is not - the share volumes that contain commas are not properly quoted. That said you'll need to employ additional knowledge. In this case, try changing the format of the output from:

http://download.finance.yahoo.com/d/quotes.csv?s=avxl,goog,aapl&f=snl1c6j2s6f6

producing:

"AVXL","ANAVEX LIFE SCIEN",0.1799,"-0.0041",    38,260,000,0,    23,703,000
"GOOG","Google Inc.",500.87,"+4.69",   678,365,000,67.911B,   572,967,000
"AAPL","Apple Inc.",109.80,"-0.42",  5,864,839,000,182.8B,  5,856,335,000

to e.g.:

http://download.finance.yahoo.com/d/quotes.csv?s=avxl,goog,aapl&f=sl1c6sj2ss6sf6

which yields:

"AVXL",0.1799,"-0.0041","AVXL",    38,260,000,"AVXL",0,"AVXL",    23,703,000
"GOOG",500.87,"+4.69","GOOG",   678,365,000,"GOOG",67.911B,"GOOG",   572,967,000
"AAPL",109.80,"-0.42","AAPL",  5,864,839,000,"AAPL",182.8B,"AAPL",  5,856,335,000

You can then parse this with e.g.:

sed 's/"[A-Z][^"]*",/ & /g' \
| awk -- '{
        gsub("\"", "", $2);
        gsub(",", "", $4);
        gsub(",", "", $8);
        print 2 6 $8
    }'

which will give you something more CSV-like:

"AVXL",0.1799,-0.0041,38260000,0,23703000
"GOOG",500.87,+4.69,678365000,67.911B,572967000
"AAPL",109.80,-0.42,5864839000,182.8B,5856335000

The trick is that the ticker symbol is a well-matchable thing and you can thus use it as an anchor where you need it.

The magic incantation above does this:

  • the sed invocation surrounds the occurrences of the ticker symbols (which are double quoted strings beginning with a capital letter) with spaces, thus marking it effectively a white-spaces separated lists

  • awk first replaces all double quotes (first line) and commas (second and third line) in fields 2 (to prevent the price change field being double quoted and thus being treated as a string instead of a floating point number if you then start processing it with a spreadsheet) and 4 and 8 respectively. The last line prints the modified fields (and omits the now superfluous additional ticker symbols).

Thus in the end you can do it like this:

curl -s 'http://download.finance.yahoo.com/d/quotes.csv?s=avxl,goog,aapl&f=sl1c6sj2ss6sf6' \
| sed 's/"[A-Z][^"]*",/ & /g' \
| awk -- '{
        gsub("\"", "", $2);
        gsub(",", "", $4);
        gsub(",", "", $8);
        print 2 6 $8
    }'

Note the \ backslashes at the end of the lines - these make sure, that the commands are not invoked separately, but rather as if they were on one line. This notation is used to enhance readability. The backslashes are not used in the four line AWK script, since that is surrounded by quotes and the new lines are thus part of the whole command. And be sure to read some basic tutorials on UNIX shell scripting - it will save you lots of time later on.

Also note the quotes around the URL - these make sure that special characters (& in this case) don't get interpreted by the shell.

Answer from peterph on Stack Exchange
Top answer
1 of 1
2

The problem is, that while the url would suggest it is a CSV, it really is not - the share volumes that contain commas are not properly quoted. That said you'll need to employ additional knowledge. In this case, try changing the format of the output from:

http://download.finance.yahoo.com/d/quotes.csv?s=avxl,goog,aapl&f=snl1c6j2s6f6

producing:

"AVXL","ANAVEX LIFE SCIEN",0.1799,"-0.0041",    38,260,000,0,    23,703,000
"GOOG","Google Inc.",500.87,"+4.69",   678,365,000,67.911B,   572,967,000
"AAPL","Apple Inc.",109.80,"-0.42",  5,864,839,000,182.8B,  5,856,335,000

to e.g.:

http://download.finance.yahoo.com/d/quotes.csv?s=avxl,goog,aapl&f=sl1c6sj2ss6sf6

which yields:

"AVXL",0.1799,"-0.0041","AVXL",    38,260,000,"AVXL",0,"AVXL",    23,703,000
"GOOG",500.87,"+4.69","GOOG",   678,365,000,"GOOG",67.911B,"GOOG",   572,967,000
"AAPL",109.80,"-0.42","AAPL",  5,864,839,000,"AAPL",182.8B,"AAPL",  5,856,335,000

You can then parse this with e.g.:

sed 's/"[A-Z][^"]*",/ & /g' \
| awk -- '{
        gsub("\"", "", $2);
        gsub(",", "", $4);
        gsub(",", "", $8);
        print 2 6 $8
    }'

which will give you something more CSV-like:

"AVXL",0.1799,-0.0041,38260000,0,23703000
"GOOG",500.87,+4.69,678365000,67.911B,572967000
"AAPL",109.80,-0.42,5864839000,182.8B,5856335000

The trick is that the ticker symbol is a well-matchable thing and you can thus use it as an anchor where you need it.

The magic incantation above does this:

  • the sed invocation surrounds the occurrences of the ticker symbols (which are double quoted strings beginning with a capital letter) with spaces, thus marking it effectively a white-spaces separated lists

  • awk first replaces all double quotes (first line) and commas (second and third line) in fields 2 (to prevent the price change field being double quoted and thus being treated as a string instead of a floating point number if you then start processing it with a spreadsheet) and 4 and 8 respectively. The last line prints the modified fields (and omits the now superfluous additional ticker symbols).

Thus in the end you can do it like this:

curl -s 'http://download.finance.yahoo.com/d/quotes.csv?s=avxl,goog,aapl&f=sl1c6sj2ss6sf6' \
| sed 's/"[A-Z][^"]*",/ & /g' \
| awk -- '{
        gsub("\"", "", $2);
        gsub(",", "", $4);
        gsub(",", "", $8);
        print 2 6 $8
    }'

Note the \ backslashes at the end of the lines - these make sure, that the commands are not invoked separately, but rather as if they were on one line. This notation is used to enhance readability. The backslashes are not used in the four line AWK script, since that is surrounded by quotes and the new lines are thus part of the whole command. And be sure to read some basic tutorials on UNIX shell scripting - it will save you lots of time later on.

Also note the quotes around the URL - these make sure that special characters (& in this case) don't get interpreted by the shell.

🌐
David Walsh
davidwalsh.name › stock-quotes-command-line
Get Stock Quotes From Command Line
April 23, 2015 - while 1 ; do clear ; for STONK in AMC AQB GME TSLA ; do echo -e -n "\e[1;36m${STONK}\t\e[1;33m" ; curl -s https://www.marketwatch.com/investing/stock/${STONK} |grep '<meta name="price" content="' |cut -d'"' -f4 ; echo -e -n "\e[0m" ; done ; sleep 60 ; done
Discussions

Bash script to pull Stock Quotes
Can this be done easily using curl? Yes if you know the name of a site that serves the data Do stock quotes require a login? Entirely up to the site you choose. Can I pull it down using json? Again entirely up to the site you choose. Is this a bash question? No. I suggest you do a google search for 'stocks quote api' and take a look at some of the results that come back. They will point you in the right direction. Once you have gotten a bit further and have some actual code you want help with, come back to us and we will be glad to assist. PLEASE don't delete this question. More on reddit.com
🌐 r/bash
11
2
August 9, 2022
Pull Stock Quote from URL?
Is there a way to pull stock info from a URL within KM or do I need to use a java script to place it into a Variable? I thought I could just use the Get URL command - but had no luck. Example: Local_VarStock = Current p… More on forum.keyboardmaestro.com
🌐 forum.keyboardmaestro.com
0
0
August 18, 2019
yql - Get stock quotes from Yahoo finance - Stack Overflow
I have been trying to fetch the stock quotes from Yahoo finance, but I have not been able to get that. I have tried YQL Console, and it is working fine in that https://developer.yahoo.com/yql/cons... More on stackoverflow.com
🌐 stackoverflow.com
Stock quotes using curl are now blocked, what now?

more info: opening that link yields:

It has come to our attention that this service is being used in violation of the Yahoo Terms of Service. As such, the service is being discontinued. For all future markets and equities data research, please refer to finance.yahoo.com.

More on reddit.com
🌐 r/linuxquestions
1
1
November 13, 2017
🌐
GitHub
gist.github.com › hagope › 76ac6955ec5f450ea036
Realtime Stock Quote from Google Finance using cURL · GitHub
August 6, 2014 - E.g: curl -A "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5" -s https://www.google.com/finance?q=$1 ... Has moved, it seems. 302 on that, and following the url gets you nowhere...
🌐
Commandlinefu
commandlinefu.com › commands › view › 2086 › command-line-to-get-the-stock-quote-via-yahoo
Command Line to Get the Stock Quote via Yahoo
May 4, 2009 - curl -s 'http://download.finance.yahoo.com/d/quotes.csv?s=csco&f=l1' Retrieve the current stock price from Yahoo Finance. The output is simply the latest price (which could be delayed).
🌐
HackerNoon
hackernoon.com › you-can-track-stock-market-data-from-your-terminal-1k1h3135
You Can Track Stock Market Data From Your Terminal | HackerNoon
January 1, 2021 - You need to provide the ticker of the stock and terminal-stocks will give you the price information of the stock. terminal-stocks uses yahoo finance’s ticker to fetch stock information.
🌐
LinuxQuestions.org
linuxquestions.org › questions › linux-desktop-74 › cli-command-to-pull-stock-price-and-volume-from-google-4175617060
CLI command to pull Stock Price and volume from Google
November 6, 2017 - I have an app that has been pulling stock data from yahoo. The part that pulls it is a Pascal program that is run by cron and executes the following
🌐
EODHD
eodhd.com › home › curl & wget stock api examples
CURL & WGET Stock API Examples | EODHD APIs Documentation
April 24, 2024 - Access our Stock API effortlessly with CURL and WGET. Explore the End of Day and Fundamental Data APIs with easy-to-follow examples
🌐
GitHub
github.com › pstadler › ticker.sh
GitHub - pstadler/ticker.sh: Real-time stock tickers from the command-line. · GitHub
It features colored output and is able to display pre- and post-market prices (denoted with *). $ curl -o ticker.sh https://raw.githubusercontent.com/pstadler/ticker.sh/master/ticker.sh
Starred by 519 users
Forked by 91 users
Languages   Shell
Find elsewhere
🌐
Change Is Inevitable
kedar.nitty-witty.com › home › technical › how to get stock quote on linux using google ,curl, grep, awk
How to Get Stock Quote on Linux using Google ,Curl, Grep, Awk | Change Is Inevitable
June 24, 2014 - It’s a sinlge line command and you get your stock’s current price. 🙂 · curl --silent -X Get "http://www.google.com/finance?q=NSE:TCS" > /tmp/ChangeIsInevitable && cat /tmp/ChangeIsInevitable | grep -m1 -E 'span id="ref_' | awk -F ">" '{print $2}' | awk -F "<" '{print $1}' This work for other Stock Exchanges like NYSE as well: curl --silent -X Get "http://www.google.com/finance?q=nyse:goog" > /tmp/bgz && cat /tmp/bgz | grep -m1 -E 'span id="ref_' | awk -F ">" '{print $2}' | awk -F "<" '{print $1}' && date 617.19 Fri Nov 12 17:07:52 IST 2010 ·
🌐
Stockmarketwatch
stockmarketwatch.com › stock
CURL Stock Quote - CURL Stock Price Today
CURL stock quote, chart and news. Get CURL's stock price today.
🌐
Yahoo! Finance
finance.yahoo.com › quote › CURLF
Curaleaf Holdings, Inc. (CURLF) Stock Price, News, Quote & History - Yahoo Finance
June 9, 2026 - Find the latest Curaleaf Holdings, Inc. (CURLF) stock quote, history, news and other vital information to help you with your stock trading and investing.
🌐
Medium
medium.com › @asadapp › how-to-get-stock-prices-api-ce88944d9cfa
How to get Stock Prices API. Introduction: Stock exchange statistics… | by berlitz medium | Medium
November 26, 2020 - FCS sets the current price for both or a single stock pair, retrieving historical stock data for one or more stocks, technical metrics for market value, and stock performance includes company sales, cash flow, earnings and financial statements. The FCS API is designed for easy access to resources. Using any programming language to hit the API URL to get an answer in the basic JSON format. Using the JavaScript (Ajax), PHP (Curl or file get content), Java OR android (HttpURLConnection), C # (httpWebRequest) or CURL command line.
🌐
GitHub
gist.github.com › 4318394
Get stock data from yahoo via curl · GitHub
Get stock data from yahoo via curl. GitHub Gist: instantly share code, notes, and snippets.
🌐
EODHD
eodhd.com › home
Stock Market Price Data API, Real-time, Fundamental APIs in JSON | Free Plan
CURL & WGET Stock API Examples · C# .NET Financial API Stock Wrapper · F Sharp (F#) Stock API Example · PHP/Laravel Example · Java Stock API Example · 6. No-Code Tools · EODHD Claude Skills: Teach Your AI Assistant the Entire Financial API · EODHD Chat GPT Assistant (Code generation) Spreadsheets for Stocks, ETFs, Mutual Funds, Forex pairs and more ·
🌐
Keyboard Maestro
forum.keyboardmaestro.com › questions & suggestions
Pull Stock Quote from URL? - Questions & Suggestions - Keyboard Maestro Discourse
August 18, 2019 - Is there a way to pull stock info from a URL within KM or do I need to use a java script to place it into a Variable? I thought I could just use the Get URL command - but had no luck. Example: Local_VarStock = Current price of AAPL https://www.google.com/search?client=safari&rls=en&q=NASDAQ:AAPL&ie=UTF-8&oe=UTF-8
🌐
API Ninjas
api-ninjas.com › api › stockprice
Stock Price API - API Ninjas
1 2 curl -X GET "https://api.api-ninjas.com/v1/stockprice?ticker=AAPL" \ -H "X-Api-Key: YOUR_API_KEY" If your programming language is not listed in the Code Example above, you can still make API calls by using a HTTP request library written in your programming language and following the above ...