LoginSignup
1
1

More than 5 years have passed since last update.

findした結果をまとめてjqコマンドで処理する

Posted at

カレントディレクトリ以下のJSONファイルに対して、まとめて jq コマンドを適用するには次のようにします。

find . -name "*.json" -exec sh -c "jq < {}" \;

例えばこんなフォーマットのJSONファイルからstringだけを抜き出したいときは、

[{"string": "abc", "number": 123}, {"string": "def", "number": 456}]

次のようにしてフィルタを適用します。

find . -name "*.json" -exec sh -c "jq '.[].string' < {}" \;

このように、 find コマンドの -execsh -c との組み合わせは、 find の結果を別なコマンドの標準入力にリダイレクトしたいときに使えます。

1
1
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
1
1