我正在尝试从命令"lsb_release“的结果创建一个JSON文件
我所做的:
if [ -x "$(command -v lsb_release)" ]; then
lsb_release -a | jq --raw-input 'split("\t") | { (.[0]) : .[1] }' > ubuntu_release.json
fi结果是
{
"Distributor ID:": "Ubuntu"
}
{
"Description:": "Ubuntu 20.04.3 LTS"
}
{
"Release:": "20.04"
}
{
"Codename:": "focal"
}但我想知道结果
[
{
"Distributor ID:": "Ubuntu"
},
{
"Description:": "Ubuntu 20.04.3 LTS"
},
{
"Release:": "20.04"
},
{
"Codename:": "focal"
}
]有人能帮我吗?)
发布于 2022-04-27 06:24:08
过滤器
reduce (inputs / ":\t") as [$key, $value] ({}; .+{($key): $value})输入
Distributor ID: Ubuntu
Description: Ubuntu 20.04.3 LTS
Release: 20.04
Codename: focal输出
{
"Distributor ID": "Ubuntu",
"Description": "Ubuntu 20.04.3 LTS",
"Release": "20.04",
"Codename": "focal"
}请注意,来自$key和$value的inputs的每一行都是由reduce处理和组合的。
演示
https://stackoverflow.com/questions/70804610
复制相似问题