LoginSignup
2
2

More than 5 years have passed since last update.

タイムスタンプを→日付に変換しながら tail とか

Posted at
tt
#!/usr/bin/php
<?php
while($line = fgets(STDIN)) {
    // now: 1326356996
    // 6年前~14年後くらいまで大丈夫
    echo preg_replace_callback(
        '/ (1[2-7]\d{8}) /',
        function ($m) use ($argv) {
            $ts = $m[1];
            $dt = new \DateTime('@' . $ts);
            $dt->setTimeZone(new \DateTimeZone(isset($argv[1]) ? $argv[1] : 'Asia/Tokyo'));
            return ' ' . $dt->format('Y-m-d H:i:s') . ' ';
        },
        $line
    );
}

で、適当に実行権限あたえてpathとおして

$ cat hoge.txt | tt

とかしてる

$ tail -f /path/to/log | tt 'UTC'

とか。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2