Running
yq eval --null-input '.a.b = "cat" | .x = "frog"'
will output
a:b: catx: frog
Given a sample.yml file of:
a:b:g: foof
then
yq eval '.a |= .b' sample.yml
will output
a:g: foof
Note this will also work when the second file is a scalar (string/number)
Given a sample.yml file of:
a: apples
And another sample another.yml file of:
b: bob
then
yq eval-all 'select(fileIndex==0).a = select(fileIndex==1) | select(fileIndex==0)' sample.yml another.yml
will output
a:b: bob
Given a sample.yml file of:
a:b: childb: sibling
then
yq eval '.a = .b' sample.yml
will output
a: siblingb: sibling
Given a sample.yml file of:
a: fieldAb: fieldBc: fieldC
then
yq eval '(.a, .c) |= "potatoe"' sample.yml
will output
a: potatoeb: fieldBc: potatoe
Given a sample.yml file of:
a:b: apple
then
yq eval '.a.b = "frog"' sample.yml
will output
a:b: frog
Note there is no difference between =
and |=
when the RHS is a scalar
Given a sample.yml file of:
a:b: apple
then
yq eval '.a.b |= "frog"' sample.yml
will output
a:b: frog
Given a sample.yml file of:
a:b: applec: cactus
then
yq eval '(.a[] | select(. == "apple")) = "frog"' sample.yml
will output
a:b: frogc: cactus
Given a sample.yml file of:
- candy- apple- sandy
then
yq eval '(.[] | select(. == "*andy")) = "bogs"' sample.yml
will output
- bogs- apple- bogs
Given a sample.yml file of:
{}
then
yq eval '.a.b |= "bogs"' sample.yml
will output
{a: {b: bogs}}
Given a sample.yml file of:
{}
then
yq eval '.a.b.[0] |= "bogs"' sample.yml
will output
{a: {b: [bogs]}}