6

I have a simple values.yaml file which has below data:

images:
  tags:
    one: abc:v0.3-16-07
    two: xyz:ng-0.23.0
    pq: qaa:0df1e21e752b3d3.2020-04-27_1

Using

yq -r --yaml-output ".images.tags" values.yaml

I can get below output

one: abc:v0.3-16-07
two: xyz:ng-0.23.0
pq: qaa:0df1e21e752b3d3.2020-04-27_1

But how can i get the values from the above?

Inian
  • 80,270
  • 14
  • 142
  • 161
Saurabh Arora
  • 377
  • 2
  • 4
  • 11

2 Answers2

8

You don't need to use --yaml-output flag, which tries to parse the output of the filter defined as a YAML entity. For getting the raw strings, use a filter in the JSON context itself

yq -r '.images.tags[]'
Inian
  • 80,270
  • 14
  • 142
  • 161
  • If only the values are needed then you could simplify to `yq -r '.images.tags[]' input`. – luciole75w May 13 '20 at 18:45
  • @luciole75w: I was actually thinking OP wanted the second part of values, so used the `to_entries` with `split()`. Made the edit now – Inian May 13 '20 at 18:50
1

Found the answer, Inian kind of posted an answer but there was a small change

yq -r '.images.tags | to_entries[].value | split(":")[0]' values.yaml

Saurabh Arora
  • 377
  • 2
  • 4
  • 11