0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

jq コマンド sed もあるよ Linux

Last updated at Posted at 2024-01-26

願望

記述形式をまとめたい

jq

// 表示結果から " , などの区切り記号を除外
jq -r

// 表示項目の途中に特定の構文記号(改行やタブなど)を追加
jq ' .[] | .ddd + "\n" + .dddd + "\t" '

// 条件式がtrueである物のみ対象とする
jq ' .[] | select(.text != "null") | .text'

// 要素の存在有無
jq ' .[] | select(has(\"text\")) | .text'
複数の値を抜き出す
// カンマで区切れば複数指定可能
jq ".[].Id,.[].value"
// [ ] で囲んで [ , ]形式で表示
jq "[.[].Id,.[].value]"
// |@csv で1行にまとめて表示
jq "[.[].Id,.[].value]|@csv"

// |@tsv で1行にまとめて表示して、" と /t を外して綺麗に表示
jq "[.[].Id,.[].value]|@tsv" | sed -e 's/\"//g' | sed -e 's/\\t/,/g'
jq -r "[.[].Id,.[].value]|@tsv" | sed -e 's/\"//g' | sed -e 's/\\t/,/g'

sed

sed
# ダブルクォーテーション、タブ を除去
sed -e 's/\"//g' | sed -e 's/\\t/,/g'

# その他
| sed 's/|.*$//g' | sed 's/[<>]//g'"

参考

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?