How to search array in array with dynamic variables using yq #1255
Unanswered
dnyaneshwarjadhav
asked this question in
Q&A
Replies: 2 comments
-
@mikefarah any suggestions on this ? |
Beta Was this translation helpful? Give feedback.
0 replies
-
I'm not 100% sure what you are trying to do - I think you are trying to find entries in target.yml that have a matching name from sample.yml? I updated your sample.yaml to include matching data: sample.yaml
so that: yq '.[] | select( .name == (load("sample.yaml") | .[].name ) )' target.yaml results in:
Explanation:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am having json file as
sample.json
Another YAML file(target.yaml)
I wanted to get final result as data from YAML file and perform contains operation on data from sample.json file.
I tried with following way
yq e '. | .[].name | contains("default","default1")'
sample.jsonThis is giving result as follow:-
$ yq e '. | .[].name | contains("default","default1")' myres.txt
false
false
false
false
true
false
Another approach tries is
myarr=$(yq e '. | .[].name ' target.yaml)
# Put array into myarr variableyq e '. | .[].name | contains(myarr)' sample.json
# This wont workyq e '. | .[].name | contains(env(myarr))' sample.json
# This wont work eitherExpecting result should be
Beta Was this translation helpful? Give feedback.
All reactions