Difference between revisions of "yq parser"
From thelinuxwiki
(Created page with "file contents: <source lang="yaml"> webserver: hosts: foo: ipaddr: 192.168.1.1 desc: "foo" bar: ipaddr: 10.0.0.1 desc: "bar" </source> $ '...") |
|||
(3 intermediate revisions by one user not shown) | |||
Line 1: | Line 1: | ||
− | file contents: | + | file name foobarr.yml contents: |
<source lang="yaml"> | <source lang="yaml"> | ||
webserver: | webserver: | ||
Line 12: | Line 12: | ||
− | $ '''yq '. | + | $ '''yq '.webserver.hosts[] | select(.ipaddr == "192.168.1.1")' foobar.yml''' |
{ | { | ||
− | "ipaddr": " | + | "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''' |
Latest revision as of 21:36, 21 May 2025
file name foobarr.yml contents:
webserver: hosts: foo: ipaddr: 192.168.1.1 desc: "foo" bar: ipaddr: 10.0.0.1 desc: "bar"
$ 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