示例: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