1

Example: Google's Outstanding Shares are 670,000,000 and this value is collected in a txt file from Yahoo Finance API using the below script.

The issue is; that numbers WITH commas or spaces are near impossible for the text wizard and Excel to delimit when I pull this txt file into Excel to complete my work.

Ie the delimiter wants to break 670,000,000 into three separate values AND spread this across three columns which is a joke and renders my work futile.

Thus: I need the prospective script to bring all numerical strings that originally contained commas and spaces back to the txt file WITHOUT such. Ie no commas or no spaces.

So rather than 670,000,000 being brought into the txt file, I need 670000000 so that Excels antiquated delimiter may render the data into columns properly.

I have asked this question 4 times on here and each time the code provided by the super user has not worked.

cd desktop/quoteUpdate
while true
do
  curl -o quotes.txt -s "http://download.finance.yahoo.com/d/quotes.csv?s=goog,aapl&f=nsl1j2"
echo UPDATED:
date
sleep 10
Done

marked as duplicate by jimmij, John WH Smith, Networker, jasonwryan, Anthon Jan 20 '15 at 18:37

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

You could add a sed command after the curl command to replace commas inside numbers:

cd desktop/quoteUpdate
while true
do
  curl -o quotes.txt -s "http://download.finance.yahoo.com/d/quotes.csv?s=goog,aapl&f=nsl1j2"
  sed -i -E 's:([0-9]),([0-9]):\1\2:g' quotes.txt
echo UPDATED:
date
sleep 10
Done

The result will look like this:

"Google Inc.","GOOG",508.08,   678365000
"Apple Inc.","AAPL",105.99,  5864839000

enter image description here

  • really appreciate the help. Will try this out and revert back. Thank you – Chris Dormani Jan 17 '15 at 19:44
  • I used the code you kindly issued and it makes no difference. The values do not arrive as you said in the result above minus the commma. I also get a note when I run the file saying sed: 1: "s:([0-9]),([0-9]):\1\2:g": \1 not defined in the RE – Chris Dormani Jan 19 '15 at 12:57
  • I update my answer with an screenshot where you can see that the solution works. Seems that you are getting a error on sed command. The output of sed --version will help. – jherran Jan 19 '15 at 15:03
  • Hi there. What are you suggesting that I do to the script. Thanks – Chris Dormani Jan 19 '15 at 15:37
  • Execute the couple of commands I did in the screenshots and paste the results. Additionally, paste the output of sed --version. – jherran Jan 19 '15 at 16:17

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