SBI証券のポートフォリオのCSVファイルの文字コードをUTF-8に変換する
2021/04/09
問題
SBI証券のポートフォリオのページからダウンロードしたCSVファイルが文字化けしている
$ cat New_file.csv
"|[gtHIꗗ",
"ꊇ\",
"PTS\",
"F8",
"ÍF1-8",
"y[WF1",
"Miz/aj",
"t@h","t","","擾P","ݒl","O","Oij","v","vij","]z",
"OHteiہ|l`whr@rčiroTOOj","----/--/--",195173,15371,15368,-3,-0.02,-58.55,-0.02,299941.86,
"a|eobW@m`rc`pPOO","----/--/--",9974,26688,28462,-4,-0.01,+1769.38,+6.65,28387.99,
"M(z/a)v",
"]z","܂ݑv","܂ݑvij","O","Oij",
328329.86,+1710.83,+0.52,-62.54,-0.02,
"Miz/݂ NISAaj",
"t@h","t","","擾P","ݒl","O","Oij","v","vij","]z",
"OHteiہ|l`whr@r@ioρj","----/--/--",34045,11749,13636,+106,+0.78,+6424.29,+16.06,46423.76,
"OHteiہ|l`whr@rčiroTOOj","----/--/--",35793,13038,15368,-3,-0.02,+8339.76,+17.87,55006.68,
"OHteiہ|l`whr@r@oXiWYϓ^j","----/--/--",33003,11614,12846,+23,+0.18,+4065.96,+10.61,42395.65,
"OHteiہ|l`whr@r@SEiI[EJg[j","----/--/--",21630,12329,14548,+4,+0.03,+4799.69,+18.00,31467.32,
"OHteiہ|l`whr@r@iCfbNX","----/--/--",22441,14112,16589,-7,-0.04,+5558.63,+17.55,37227.37,
"rah|rahEoK[hEroTOOCfbNXEt@h","----/--/--",20826,13605,14100,-4,-0.03,+1030.88,+3.64,29364.66,
"M(z/݂ NISAa)v",
"]z","܂ݑv","܂ݑvij","O","Oij",
241885.45,+30219.24,+14.28,+410.66,+0.17,
"v",
"]z","܂ݑv","܂ݑvij","l","lij",
570215.32,+31930.08,+5.93,0,0
原因
文字コードがShift-JISだったから
unknown-8bitはShift-JISのことみたい
$ file --mime New_file.csv
New_file.csv: text/plain; charset=unknown-8bit
解決方法
UTF-8に変換する
$ iconv -f SHIFT_JIS -t UTF-8 New_file.csv > New_file.utf-8.csv
$ cat New_file.utf-8.csv
"ポートフォリオ一覧",
"一括表示",
"PTS株価表示",
"総件数:8件",
"選択範囲:1-8件",
"ページ:1",
"投資信託(金額/特定預り)",
"ファンド名","買付日","数量","取得単価","現在値","前日比","前日比(%)","損益","損益(%)","評価額",
"三菱UFJ国際−eMAXIS Slim米国株式(S&P500)","----/--/--",195173,15371,15368,-3,-0.02,-58.55,-0.02,299941.86,
"大和−iFreeレバレッジ NASDAQ100","----/--/--",9974,26688,28462,-4,-0.01,+1769.38,+6.65,28387.99,
"投資信託(金額/特定預り)合計",
"評価額","含み損益","含み損益(%)","前日比","前日比(%)",
328329.86,+1710.83,+0.52,-62.54,-0.02,
"投資信託(金額/つみたてNISA預り)",
"ファンド名","買付日","数量","取得単価","現在値","前日比","前日比(%)","損益","損益(%)","評価額",
"三菱UFJ国際−eMAXIS Slim 国内株式(日経平均)","----/--/--",34045,11749,13636,+106,+0.78,+6424.29,+16.06,46423.76,
"三菱UFJ国際−eMAXIS Slim米国株式(S&P500)","----/--/--",35793,13038,15368,-3,-0.02,+8339.76,+17.87,55006.68,
"三菱UFJ国際−eMAXIS Slim バランス(8資産均等型)","----/--/--",33003,11614,12846,+23,+0.18,+4065.96,+10.61,42395.65,
"三菱UFJ国際−eMAXIS Slim 全世界株式(オール・カントリー)","----/--/--",21630,12329,14548,+4,+0.03,+4799.69,+18.00,31467.32,
"三菱UFJ国際−eMAXIS Slim 先進国株式インデックス","----/--/--",22441,14112,16589,-7,-0.04,+5558.63,+17.55,37227.37,
"SBI−SBI・バンガード・S&P500インデックス・ファンド","----/--/--",20826,13605,14100,-4,-0.03,+1030.88,+3.64,29364.66,
"投資信託(金額/つみたてNISA預り)合計",
"評価額","含み損益","含み損益(%)","前日比","前日比(%)",
241885.45,+30219.24,+14.28,+410.66,+0.17,
"総合計",
"評価額","含み損益","含み損益(%)","基準値比","基準値比(%)",
570215.32,+31930.08,+5.93,0,0