我想在输出标题中打印"/"
分隔符。
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
输出如下:
| version | GPU_driver | miner | gpu |
| ------- | ---------- | -------- | --- |
| 1.2.3 | nvidia | ethminer | 22 |
| 1.2.4 | amdgpu | ethminer | 11 |
但我想在gpu title里面的数字之间找到分隔符,如下所示:
| version | GPU_driver | miner | gpu |
| ------- | ---------- | -------- | ---- |
| 1.2.3 | nvidia | ethminer | 2/2 |
| 1.2.4 | amdgpu | ethminer | 1/1 |
答案 0 :(得分:1)
由于您已对该特定字段使用string interpolation,只需在字符串中包含所需字符(斜杠IdentityUserRole
),如下所示:
/
在你的情况下(完整的一行):
curl ... | jq -c '... [.version,.driver,.miner,"\(.gpus)/\(.miner_instance)"] ...'
答案 1 :(得分:1)
您只是为了处理数据而进行了大量不必要的调用。您的命令可以大大简化。
.rigs
对象以获取其值,您只需使用[]
访问它们。-r
。所以你的命令变成了这个:
$ 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
答案 2 :(得分:0)
以下是一些简化建议:
--raw-output
选项jq
删除多余的反斜杠csvlook
为您执行此操作.[]
以下是一个例子:
(
echo version,GPU_driver,miner,gpu
curl -s 'http://cd0a4a.ethosdistro.com/?json=yes' |
jq -r '
.rigs | .[] |
[ .version, .driver , .miner , "\(.gpus)/\(.miner_instance)" ] |
@csv
'
) |
csvlook
输出:
|----------+------------+----------+------|
| version | GPU_driver | miner | gpu |
|----------+------------+----------+------|
| 1.2.3 | nvidia | ethminer | 2/2 |
| 1.2.4 | amdgpu | ethminer | 1/1 |
|----------+------------+----------+------|