jq在输出内部打印字符 [英] jq print character inside output
本文介绍了jq在输出内部打印字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在输出标题中打印"/"
分隔符.
I want print "/"
separator inside output title.
curl -s http://cd0a4a.ethosdistro.com/?json=yes \
| jq -c '.rigs|."0d6b27",."50dc35"|[.version,.driver,.miner,"\(.gpus)\(.miner_instance)"]|@csv' \
| sed 's/\\//g;s/\"//g' \
| gawk 'BEGIN{print "version" "," "GPU_driver" "," "miner" "," "gpu"} {print $0}' \
| csvlook -I
输出是这样的:
The output is like this :
| version | GPU_driver | miner | gpu |
| ------- | ---------- | -------- | --- |
| 1.2.3 | nvidia | ethminer | 22 |
| 1.2.4 | amdgpu | ethminer | 11 |
但是我想要在gpu标题内的数字之间使用分隔符,如下所示:
But I want separator in between the numbers inside gpu title like this :
| version | GPU_driver | miner | gpu |
| ------- | ---------- | -------- | ---- |
| 1.2.3 | nvidia | ethminer | 2/2 |
| 1.2.4 | amdgpu | ethminer | 1/1 |
推荐答案
您正在做很多不必要的调用,只是为了处理数据.您的命令可以大大简化.
You're doing a lot of unnecessary calls just to process the data. Your commands could be drastically simplified.
- 您无需显式键入
.rigs
对象即可获取它们的值,只需使用[]
即可访问它们. - 您不需要sed调用来去除引号,只需使用原始输出
-r
. - 您不需要awk调用来添加标题,您只需从jq输出另外一行即可.
- You don't need to explicitly key into the
.rigs
object to get their values, you could just access them using[]
. - You don't need the sed call to strip the quotes, just use the raw output
-r
. - You don't need the awk call to add the header, you could just output an additional row from jq.
因此,您的命令改为:
$ curl -s http://cd0a4a.ethosdistro.com/?json=yes \
| jq -r '["version", "GPU_driver", "miner", "gpu"],
(.rigs[] | [.version, .driver, .miner, "\(.gpus)/\(.miner_instance)"])
| @csv' \
| csvlook -I
这篇关于jq在输出内部打印字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文