Last active
January 10, 2018 11:41
-
-
Save tacmasi/3679cf276335afb0e63ecf8a50aae41e to your computer and use it in GitHub Desktop.
内閣府Webサイトから四半期名目GDPをgetする( Bash & awk ) ref: https://qiita.com/tacmasi/items/8ef36aea5bb0ea3dadd9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./gdpget.sh | |
(略) | |
nominalgdp.csvへ名目GDPデータを保存しました | |
$ head -3 nominalgdp.csv | |
time,国内総生産(支出側),民間最終消費支出,家計消費,持家帰属家賃を除く家計消費,民間住宅,民間企業設備,民間在庫変動,政府最終消費支出,公的固定資本形成,純輸出,輸出,輸入 | |
1994/1-3.,12796.3,6829.3,6215.9,5617.9,984.4,2312.5,-480.9,1358.4,1191.5,-113.7,714.8,1249.3 | |
4-6.,12571.1,6713.6,6447.8,5747.1,320.7,1545.6,820.6,2182.0,672.2,31.8,284.6,1981.7 | |
$ tail -3 nominalgdp.csv | |
2017/1-3.,13617.5,7058.5,7411.6,6932.7,303.3,2086.5,-960.8,2349.5,539.9,8.2,232.5,2936.4 | |
4-6.,13533.1,7956.0,7933.0,6450.6,212.8,1283.9,110.9,2360.8,737.8,0.6,870.2,2092.4 | |
7-9.,13285.3,7531.6,7560.7,6067.4,527.5,2195.5,171.1,2566.3,593.9,1.7,697.6,2828.8 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
wget http://www.esri.cao.go.jp/jp/sna/sokuhou/sokuhou_top.html -O sokuhou_top.html | |
wget http://www.esri.cao.go.jp/jp/sna/sokuhou/$(cat sokuhou_top.html |sed -e 's/\r//g' -e 's/href="/href="\n/g' -e 's/html"/html\n"/g' |grep -a1 統計表一覧|head -1) -O gdemenuja.html | |
curl http://www.esri.cao.go.jp/$(cat gdemenuja.html |sed -e 's/\r//g'|grep csv|grep 名目原系列|sed -e 's/href="/href="\n/g' -e 's/csv"/csv\n"/g'|grep gaku|grep -v kgaku)|nkf > tmpa | |
cat tmpa|awk -F, 'NR==3||NR==4||NR>=8{print}END{}'|sed -e 's/[0-9],\([0-9]\{3\}\)./\1./g' -e 's/"//g'|awk -F, 'BEGIN{OFS=","}NR==1{NF=13;$1="time";$4="家計消費";$5="持家帰属家賃を除く家計消費";$11="純輸出";$12="輸出";$13="輸入";print}NR>=3{NF=13;print}'|sed -e 's/\t/,/g' -e 's/ //g' >nominalgdp.csv | |
rm sokuhou_top.html gdemenuja.html tmpa | |
echo nominalgdp.csvへ名目GDPデータを保存しました |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment