Created
September 29, 2016 16:04
-
-
Save rsky/596d1a025ed6ddef9292bedb5679a6ca to your computer and use it in GitHub Desktop.
航海日誌 (logbook/logbook-kai) の資材ログを日付ごとにまとめるスクリプト
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
#!/usr/bin/env php | |
<?php | |
/** | |
* Usage: | |
* php aggr.php < 資材ログ.csv > out.csv | |
* nkf -Ws -Lw out.csv > 資材ログ.csv | |
*/ | |
$src = 'php://filter/read=convert.iconv.cp932%2Futf-8/resource=php://stdin'; | |
$file = new SplFileObject($src); | |
$file->setFlags(SplFileObject::DROP_NEW_LINE); | |
$lines = []; | |
foreach ($file as $line) { | |
$date = explode(' ', $line, 2)[0]; | |
$lines[$date] = $line . "\n"; | |
} | |
file_put_contents('php://stdout', $lines); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment