Ask Your Question
1

What is the method of obtaining the key and value using yq V4.x.x?

asked 2022-05-10 11:00:00 +0000

plato gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-05-03 03:00:00 +0000

lakamha gravatar image

To obtain the key and value using yq V4.x.x, you can use the select function.

For example, if you have a YAML file with the following content:

apple: fruit
carrot: vegetable

You can obtain the key and value of the apple key using the following command:

yq eval '.apple | select(dict: .)' file.yaml

This will output:

apple: fruit

The select function takes a dict argument that specifies the key-value pairs to select. In this case, we are selecting the key-value pair where the key equals apple.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-05-10 11:00:00 +0000

Seen: 13 times

Last updated: May 03 '22