gpt4 book ai didi

json - 如何使用 jq 将多个字段连接到同一行

转载 作者:行者123 更新时间:2023-11-29 09:41:54 25 4
gpt4 key购买 nike

<分区>

如果我运行:

cat <file> | jq 

我得到:

{
"user": "alex",
"num": "486",
"time": "Thu Jun 6 16:26:06 PDT 2019",
"pwd": "/Users/alex/codes/ores/prompt-command",
"pid": 11047,
"exit_code": 0,
"cmd": "echo '123'"
}
{
"user": "john",
"num": "487",
"time": "Thu Jun 6 16:26:24 PDT 2019",
"pwd": "/Users/alex/codes/ores/prompt-command",
"pid": 11108,
"exit_code": 5,
"cmd": "echo '456'"
}
{
"user": "alex",
"num": "488",
"time": "Thu Jun 6 16:26:59 PDT 2019",
"pwd": "/Users/alex/codes/ores/prompt-command",
"pid": 11141,
"exit_code": 5,
"cmd": "echo '789'"
}

但不是所有这些字段,我只想要一些输出,例如:

alex echo '123'
alex echo '789'

所以我试了一下:

cat <file> | jq -r '.user .cmd'

但这没有用,我得到了这个错误:

jq: error (at :63): Cannot index string with string "cmd"

我也想过滤它,所以我只看到我的命令,比如:

cat <file> | jq -r '.user=alex .cmd'

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com