Get all keys values using yq if a given string matches in YAML

Viewed 3018

I have below yaml file and I am trying to get all key value pairs if abc string is present in values.

a: abcsdf
b: hyuabc
c: iopabc
d: mnhbvgc

Expected output:

a: abcsdf
b: hyuabc
c: iopabc

My Attempt:

yq eval '.[] | select(. == "*abc*") test.yaml
1 Answers

It is really weird, the select and del functions in work totally different. While select returns the result of the filter as the array elements, delete returns the map

yq eval 'del( .[] | select( . != "*abc*" ) )' yaml
Related