I am running a puppet bolt command query certain information from a set of servers in json format. I am piping it to jq.. Below is what I get
$ bolt command run "cat /blah/blah" -n @hname.txt -u uid --no-host-key-check --format json |jq -jr '.items[]|[.node],[.result.stdout]'
[
"node-name"
][
"stdout data\n"
]
What do I need to do to make it appear like below
["nodename":"stdout data"]
如果您真的想要无效的 JSON 输出,则必须构造输出字符串,这可以使用字符串插值轻松完成,例如:
jq -r '.items[] | "[\"\(.node)\",\"\(.result.stdout)\"]"'
@peak thank you.. that helped. Below is how it looks like
$ bolt command run "cat /blah/blah" -n @hname.txt -u UID --no-host-key-check --format json |jq -r '.items[] | "[\"\(.node)\",\"\(.result.stdout)\"]"'
["node name","stdout data
"]
I used a work around to get the data I needed by using the @csv flag to the command itself. Sharing with you below what worked.
$ bolt command run "cat /blah/blah" -n @hname.txt -u uid --no-host-key-check --format json |jq -jr '.items[]|[.node],[.result.stdout]|@csv'
""node-name""stdout.data
"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.