mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
847 B
847 B
Tag
The tag operator can be used to get or set the tag of nodes (e.g. !!str
, !!int
, !!bool
).
{% hint style="warning" %} Note that versions prior to 4.18 require the 'eval/e' command to be specified.
yq e <exp> <file>
{% endhint %}
Get tag
Given a sample.yml file of:
a: cat
b: 5
c: 3.2
e: true
f: []
then
yq '.. | tag' sample.yml
will output
!!map
!!str
!!int
!!float
!!bool
!!seq
Set custom tag
Given a sample.yml file of:
a: str
then
yq '.a tag = "!!mikefarah"' sample.yml
will output
a: !!mikefarah str
Find numbers and convert them to strings
Given a sample.yml file of:
a: cat
b: 5
c: 3.2
e: true
then
yq '(.. | select(tag == "!!int")) tag= "!!str"' sample.yml
will output
a: cat
b: "5"
c: 3.2
e: true