Last active
March 9, 2017 21:44
-
-
Save stknohg/faeb5ad760fc6097c0eac938048c58f6 to your computer and use it in GitHub Desktop.
例のCSVをアレするアレ
This file contains 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
# 面倒なので適当 | |
"http://www8.cao.go.jp/chosei/shukujitsu/syukujitsu.csv" ` | |
| % { (curl $_).Content } ` | |
| % { [Text.Encoding]::GetEncoding(932).GetString([Text.Encoding]::GetEncoding("ISO-8859-1").GetBytes($_)) -split "`r`n" } ` | |
| ? { $_ -ne "" -and $_ -notlike "*,,,,," } ` | |
| select -Skip 2 ` | |
| % { $cs = $_ -split ','; for( $i=0; $i -lt $cs.Length; $i+=2 ){ [PSCustomObject]@{Date=[Datetime]$cs[$i+1];Name=$cs[$i]} } } ` | |
| sort Date ` | |
| ConvertTo-Csv -NoTypeInformation |
This file contains 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
# ConvertFrom-Csv使った版 | |
"http://www8.cao.go.jp/chosei/shukujitsu/syukujitsu.csv" ` | |
| % { (curl $_).Content } ` | |
| % { [Text.Encoding]::GetEncoding(932).GetString([Text.Encoding]::GetEncoding("ISO-8859-1").GetBytes($_)) -split "`r`n" } ` | |
| ? { $_ -ne "" -and $_ -notlike "*,,,,," } ` | |
| select -Skip 2 ` | |
| ConvertFrom-Csv -Header (1..3|%{"N$_","D$_"}) -PipelineVariable R ` | |
| % { 1..3 | % { [PSCustomObject]@{ Date=[Datetime]$R.$("D$_"); Name=$R.$("N$_")} } } ` | |
| sort Date ` | |
| ConvertTo-Csv -NoTypeInformation |
例のCSVが割と普通のCSVに変わったのでコレはもうお役御免です(:
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
結果