Subtract
You can use subtract to subtract numbers as well as remove elements from an array.
Array subtraction
Running
yq --null-input '[1,2] - [2,3]'will output
- 1Array subtraction with nested array
Running
yq --null-input '[[1], 1, 2] - [[1], 3]'will output
- 1
- 2Array subtraction with nested object
Note that order of the keys does not matter
Given a sample.yml file of:
then
will output
Number subtraction - float
If the lhs or rhs are floats then the expression will be calculated with floats.
Given a sample.yml file of:
then
will output
Number subtraction - int
If both the lhs and rhs are ints then the expression will be calculated with ints.
Given a sample.yml file of:
then
will output
Decrement numbers
Given a sample.yml file of:
then
will output
Date subtraction
You can subtract durations from dates. Assumes RFC3339 date time format, see date-time operators for more information.
Given a sample.yml file of:
then
will output
Date subtraction - custom format
Use with_dtf to specify your datetime format. See date-time operators for more information.
Given a sample.yml file of:
then
will output
Custom types: that are really numbers
When custom tags are encountered, yq will try to decode the underlying type.
Given a sample.yml file of:
then
will output
Last updated
Was this helpful?