mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
1.6 KiB
1.6 KiB
Mulitply Operator
Examples
Merge objects together
sample.yml:
{a: {also: me}, b: {also: {g: wizz}}}
Expression
yq '. * {"a":.b}' < sample.yml
Result
{a: {also: {g: wizz}}, b: {also: {g: wizz}}}
Merge keeps style of LHS
sample.yml:
a: {things: great}
b:
also: "me"
Expression
yq '. * {"a":.b}' < sample.yml
Result
a: {things: great, also: "me"}
b:
also: "me"
Merge arrays
sample.yml:
{a: [1,2,3], b: [3,4,5]}
Expression
yq '. * {"a":.b}' < sample.yml
Result
{a: [3, 4, 5], b: [3, 4, 5]}
Merge to prefix an element
sample.yml:
{a: cat, b: dog}
Expression
yq '. * {"a": {"c": .a}}' < sample.yml
Result
{a: {c: cat}, b: dog}
Merge with simple aliases
sample.yml:
{a: &cat {c: frog}, b: {f: *cat}, c: {g: thongs}}
Expression
yq '.c * .b' < sample.yml
Result
{g: thongs, f: *cat}
Merge does not copy anchor names
sample.yml:
{a: {c: &cat frog}, b: {f: *cat}, c: {g: thongs}}
Expression
yq '.c * .a' < sample.yml
Result
{g: thongs, c: frog}
Merge with merge anchors
sample.yml:
foo: &foo
a: foo_a
thing: foo_thing
c: foo_c
bar: &bar
b: bar_b
thing: bar_thing
c: bar_c
foobarList:
b: foobarList_b
<<: [*foo,*bar]
c: foobarList_c
foobar:
c: foobar_c
<<: *foo
thing: foobar_thing
Expression
yq '.foobar * .foobarList' < sample.yml
Result
c: foobarList_c
<<: [*foo, *bar]
thing: foobar_thing
b: foobarList_b