1
0
mirror of https://github.com/taigrr/yq synced 2025-01-18 04:53:17 -08:00
yq/pkg/yqlib/doc/String Operators.md
2021-04-15 16:09:47 +10:00

1.1 KiB

String Operators

Join strings

Given a sample.yml file of:

- cat
- meow
- 1
- null
- true

then

yq eval 'join("; ")' sample.yml

will output

cat; meow; 1; ; true

Substitute / Replace string

This uses golang regex, described here

Given a sample.yml file of:

a: dogs are great

then

yq eval '.a |= sub("dogs", "cats")' sample.yml

will output

a: cats are great

Substitute / Replace string with regex

This uses golang regex, described here

Given a sample.yml file of:

a: cat
b: heat

then

yq eval '.[] |= sub("([a])", "${1}r")' sample.yml

will output

a: cart
b: heart

Split strings

Given a sample.yml file of:

cat; meow; 1; ; true

then

yq eval 'split("; ")' sample.yml

will output

- cat
- meow
- "1"
- ""
- "true"

Split strings one match

Given a sample.yml file of:

word

then

yq eval 'split("; ")' sample.yml

will output

- word