Skip to content

Instantly share code, notes, and snippets.

@rsky
Created September 29, 2016 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsky/596d1a025ed6ddef9292bedb5679a6ca to your computer and use it in GitHub Desktop.
Save rsky/596d1a025ed6ddef9292bedb5679a6ca to your computer and use it in GitHub Desktop.
航海日誌 (logbook/logbook-kai) の資材ログを日付ごとにまとめるスクリプト
#!/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