Difference between revisions of "yq parser"
From thelinuxwiki
| Line 26: | Line 26: | ||
"bar" | "bar" | ||
"foo" | "foo" | ||
| + | |||
| + | csv of key + ipaddr (without quotes), use the -r (--raw-output) option: | ||
| + | |||
| + | $ '''yq -r '.webserver.hosts | to_entries[] | "\(.key),\(.value.ipaddr)"' file.yml''' | ||
Revision as of 15:47, 23 July 2026
file name foobarr.yml contents:
webserver: hosts: foo: ipaddr: 192.168.1.1 desc: "foo is cool" bar: ipaddr: 10.0.0.1 desc: "bar is cooler"
$ yq '.webserver.hosts[] | select(.ipaddr == "192.168.1.1")' foobar.yml
{
"ipaddr": "192.168.1.1"
}yq '.webserver.hosts[] | select(.ipaddr == "192.168.1.1")' foobar.yml
pass an arg
$ yq --arg IPADDR "$ipaddr" '.webserver.hosts[] | select(.ipaddr == "192.168.1.1")' foobar.yml
show only keys
$ yq '.webserver.hosts | keys | .[]' foobar.yml "bar" "foo"
csv of key + ipaddr (without quotes), use the -r (--raw-output) option:
$ yq -r '.webserver.hosts | to_entries[] | "\(.key),\(.value.ipaddr)"' file.yml