環境
CentOS6.8
要求
- jsonデータを整形したいので、jqコマンドをCentOSにインストールしたい。
- 複数ファイルを一括整形したいので、ターミナルで実行する必要がある。
- 数が少なかったら、ネット上のjsonデータ整形サービスを使用するのがおすすめ。例えば、
https://lab.syncer.jp/Tool/JSON-Viewer/ など
まず、yumでインストールを試してみる
sudo yum -y install jq
読み込んだプラグイン:fastestmirror, priorities, refresh-packagekit, security
インストール処理の設定をしています
Loading mirror speeds from cached hostfile
パッケージ jq は利用できません。
エラー: 何もしません
パッケージには入っていないようです。
CentOS7以降だといけるんですかね。
https://qiita.com/wnoguchi/items/70a808a68e60651224a4
では、公式サイトからインストールを試してみる
- 公式サイトにアクセス
- https://stedolan.github.io/jq/
- Downloadボタンをクリックし、Linux(64bit)を選択
- jq-linux64のバイナリがダウンロードされるので、/binにコピーして実行権限を付与
mv jq-linux64 /bin/jq
chmod 755 jq
インストールできたかな
[root@localhost xxxxx]# jq
jq - commandline JSON processor [version 1.5]
Usage: jq [options] <jq filter> [file...]
jq is a tool for processing JSON inputs, applying the
given filter to its JSON text inputs and producing the
filter's results as JSON on standard output.
The simplest filter is ., which is the identity filter,
copying jq's input to its output unmodified (except for
formatting).
For more advanced filters see the jq(1) manpage ("man jq")
and/or https://stedolan.github.io/jq
Some of the options include:
-c compact instead of pretty-printed output;
-n use `null` as the single input value;
-e set the exit status code based on the output;
-s read (slurp) all inputs into an array; apply filter to it;
-r output raw strings, not JSON texts;
-R read raw strings, not JSON texts;
-C colorize JSON;
-M monochrome (don't colorize JSON);
-S sort keys of objects on output;
--tab use tabs for indentation;
--arg a v set variable $a to value <v>;
--argjson a v set variable $a to JSON value <v>;
--slurpfile a f set variable $a to an array of JSON texts read from <f>;
See the manpage for more options.
- インストール出来ているようです。