2021-01-14 04:05:50 +00:00
|
|
|
# String Operators
|
2021-01-14 03:46:50 +00:00
|
|
|
|
|
|
|
## Join strings
|
|
|
|
Given a sample.yml file of:
|
|
|
|
```yaml
|
|
|
|
- cat
|
|
|
|
- meow
|
|
|
|
- 1
|
|
|
|
- null
|
|
|
|
- true
|
|
|
|
```
|
|
|
|
then
|
|
|
|
```bash
|
|
|
|
yq eval 'join("; ")' sample.yml
|
|
|
|
```
|
|
|
|
will output
|
|
|
|
```yaml
|
|
|
|
cat; meow; 1; ; true
|
|
|
|
```
|
|
|
|
|
2021-01-14 04:05:50 +00:00
|
|
|
## Split strings
|
|
|
|
Given a sample.yml file of:
|
|
|
|
```yaml
|
|
|
|
cat; meow; 1; ; true
|
|
|
|
```
|
|
|
|
then
|
|
|
|
```bash
|
|
|
|
yq eval 'split("; ")' sample.yml
|
|
|
|
```
|
|
|
|
will output
|
|
|
|
```yaml
|
|
|
|
- cat
|
|
|
|
- meow
|
|
|
|
- "1"
|
|
|
|
- ""
|
|
|
|
- "true"
|
|
|
|
```
|
|
|
|
|
|
|
|
## Split strings one match
|
|
|
|
Given a sample.yml file of:
|
|
|
|
```yaml
|
|
|
|
word
|
|
|
|
```
|
|
|
|
then
|
|
|
|
```bash
|
|
|
|
yq eval 'split("; ")' sample.yml
|
|
|
|
```
|
|
|
|
will output
|
|
|
|
```yaml
|
|
|
|
- word
|
|
|
|
```
|
|
|
|
|