LoginSignup
6
3

More than 5 years have passed since last update.

jqで複数の日付・時刻形式でstrptimeを試みる方法

Posted at
cat tmp/log | jq '. | [(.timestamp | strptime("%Y-%m-%dT%H:%M:%sZ")), (.timestamp | try strptime("%Y-%m-%dT%H:%M:%s.000Z") catch . + " hoge"), null] | first(.[] | arrays)'

各行 → JSONオブジェクト → [timestampを一つ目の形式でパースした結果, 2つ目の形式でパースした結果] → エラーでない(=arrayである)最初の値

というように変換するところがポイント。

6
3
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
6
3