<p>I have a file with three configmaps in it, like the one below.</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
data:
  TEST: &quot;one&quot;
kind: ConfigMap
metadata:
  name: test-config-one
---
apiVersion: v1
data:
  TEST: &quot;two&quot;
kind: ConfigMap
metadata:
  name: test-config-two
---
apiVersion: v1
data:
  TEST: &quot;three&quot;
kind: ConfigMap
metadata:
  name: test-config-three
</code></pre>
<p>I'm trying to apply only <code>test-config-three</code> to the cluster. I know I can break that out into its own file and run <code>kubectl apply -f test-config-three.yaml</code>, but is there a way to do that without having to create a new file?</p>
<p>I was hoping to be able to do something like:</p>
<pre class="lang-sh prettyprint-override"><code>cat file.yml | yq &lt;get only test-config-three&gt; | kubectl apply -f -
</code></pre>
<p>But <code>yq</code> doesn't seem to support finding a single resource in a file. I also looked at tools like <a href="https://github.com/looztra/kubesplit" rel="nofollow noreferrer">kubesplit</a> but they tend to output all resources to separate files.</p>
<p>Is there a way to isolate and output a single resource from a yaml file containing multiple resources without creating a new file?</p>
<p><strong>Update</strong></p>
<p>Thanks to @Inian's answer below, I was able to get this full command working.</p>
<pre class="lang-sh prettyprint-override"><code>cat file.yml | yq e 'select(.data.TEST == &quot;three&quot;)' - | kubectl apply -f -
</code></pre>

dan
<p>There are two versions of <code>yq</code> implemented, one in Python and one in Go as I've highlighted in my answer at <a href="https://stackoverflow.com/a/64742436/5291015">How can I parse a YAML file from a Linux shell script?</a></p>
<p>Using the Python version - kislyuk/yq</p>
<pre class="lang-sh prettyprint-override"><code>yq -y 'select(.data.TEST == &quot;three&quot;)' yaml
</code></pre>
<p>Go version - mikefarah/yq</p>
<pre class="lang-sh prettyprint-override"><code>yq e 'select(.data.TEST == &quot;three&quot;)' yaml
</code></pre>
