![在 Mac 上使用 cURL 命令行工具,我可以对该脚本做什么来要求它获取股票数据,这些数据将用无空格替换逗号](https://linux22.com/image/1437345/%E5%9C%A8%20Mac%20%E4%B8%8A%E4%BD%BF%E7%94%A8%20cURL%20%E5%91%BD%E4%BB%A4%E8%A1%8C%E5%B7%A5%E5%85%B7%EF%BC%8C%E6%88%91%E5%8F%AF%E4%BB%A5%E5%AF%B9%E8%AF%A5%E8%84%9A%E6%9C%AC%E5%81%9A%E4%BB%80%E4%B9%88%E6%9D%A5%E8%A6%81%E6%B1%82%E5%AE%83%E8%8E%B7%E5%8F%96%E8%82%A1%E7%A5%A8%E6%95%B0%E6%8D%AE%EF%BC%8C%E8%BF%99%E4%BA%9B%E6%95%B0%E6%8D%AE%E5%B0%86%E7%94%A8%E6%97%A0%E7%A9%BA%E6%A0%BC%E6%9B%BF%E6%8D%A2%E9%80%97%E5%8F%B7.png)
示例:Google 流通股数为 670,000,000,该值通过以下脚本从 Yahoo Finance API 收集到 txt 文件中。问题是,当我将此 txt 文件拉入 Excel 时,Excel 分隔符很难理解带有逗号或空格的数字。
注意:我需要脚本来恢复此值和所有其他值,不带逗号或空格。我需要 670000000,以便 Excel 过时的分隔符可以将数据放入列中。
我已经问过这个问题好几次了。有人能帮我解脱我的痛苦吗,在我疝气再次发作、我的苹果电脑被扔出窗外之前。谢谢。
cd desktop/quoteUpdate
while true
do
curl -o quotes.txt -s "http://download.finance.yahoo.com/d/quotes.csv?s=goog,aapl&f=nsl1c1p2j2r"
sed -i '.bak' 's/,/ /g' quotes.txt # replace commas with spaces
echo UPDATED:
date
sleep 10
done
答案1
Yahoo 的 CSV 无效,真可恶
$ cat quotes.csv
"Google Inc.","GOOG",501.79,+0.92,"+0.18%", 678,365,000,26.36
"Apple Inc.","AAPL",106.86,-2.94,"-2.68%", 5,864,839,000,17.02
$ sed 's/[[:blank:]]*\([[:digit:],]\+\)\(,[[:digit:].]\+\)/"\1"\2/' quotes.csv
"Google Inc.","GOOG",501.79,+0.92,"+0.18%","678,365,000",26.36
"Apple Inc.","AAPL",106.86,-2.94,"-2.68%","5,864,839,000",17.02