2

I am using cURL to retrieve stock information back to the terminal window on my Mac using the yahoo finance api.

i.e. I type:

curl -s 'http://download.finance.yahoo.com/d/quotes.csv?s=aapl&f=l1'

and it prints the output (in this instance the last trade price in the command line)

It works terrific, but I would like to know how to get this output automatically written to a stock.txt file located on my desktop without any manual intervention upon the execution of the original cURL command.

Thus after I type the curl query that contains the stock ticker, I get the value written in the terminal window and the txt file.

1
  • Hi, the "curl -s..." command no longer works, do you know what the updated url is? Commented Jan 18, 2021 at 18:55

3 Answers 3

5

Try this:

curl -s 'http://download.finance.yahoo.com/d/quotes.csv?s=aapl&f=l1' > ~/Desktop/stock.txt && more ~/Desktop/stock.txt

Sign up to request clarification or add additional context in comments.

2 Comments

the && more, just for my knowledge what is this doing
The && more command tells the shell to wait until output is complete to ~/Desktop/stock.txt, and then to open it up using the command more (which just views a file). The solution below uses the tee command which does this in one step.
1

You could use curl ... | tee ~/Desktop/stock.txt

Comments

0

There is also the -o/--output option:

curl -o users.json https://reqres.in/api/users

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.