Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reading values when key is with dot in yq

Tags:

yaml

yq

I am having issues reading values from yaml file when there's dot in the key name

i.e.

a:
 b.c: 2

reading the a key works fine with cat mytext.yaml | yq r - a however, when I tried reading a.b.c but it doesn't give any output.

I tried escaping the dot symbol, but doesn't give any ouput

Anything I am missing here?

like image 534
fisdaf Avatar asked Nov 24 '20 08:11

fisdaf


1 Answers

On v4 onwards, you could simply use the new syntax notation, i.e.

echo 'a:
 b.c: 2' | yq e '.a."b.c"' - 

In mikefarah/yq, you can use the quotes "..", to preserve the field containing . in your path expression as explained in the documentation Nested special characters

echo 'a:
 b.c: 2' | yq r - 'a."b.c"' 
like image 64
Inian Avatar answered Nov 22 '22 19:11

Inian