<p>this is the input</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  name: kube-vip
  namespace: kube-system
spec:
  containers:
    - args:
        - start
      env:
        - name: vip_arp
          value: &quot;true&quot;
        - name: vip_leaderelection
          value: &quot;true&quot;
        - name: vip_address
          value: 
        - name: vip_interface
          value: eth0
        - name: vip_leaseduration
          value: &quot;15&quot;
        - name: vip_renewdeadline
          value: &quot;10&quot;
        - name: vip_retryperiod
          value: &quot;2&quot;
      image: ghcr.io/kube-vip/kube-vip:v0.3.5
      imagePullPolicy: IfNotPresent
      name: kube-vip
      resources: {}
      securityContext:
        capabilities:
          add:
            - NET_ADMIN
            - SYS_TIME
      volumeMounts:
        - mountPath: /etc/kubernetes/admin.conf
          name: kubeconfig
  hostNetwork: true
  volumes:
    - hostPath:
        path: /etc/kubernetes/admin.conf
        type: FileOrCreate
      name: kubeconfig
status: {}
</code></pre>
<p>and I'd like to update the file and get the output. I can do that by using:</p>
<pre><code>cat $file | yq e '.spec.containers[].env[2].value=&quot;sdf&quot;'
</code></pre>
<p>But that assumes the index of <code>vip_address</code> env var will be always <code>2</code>. Is it possible to have something like this</p>
<pre><code>yq e '. | select(.spec.containers[].env[].name==&quot;vip_address&quot;) | .value=&quot;sdf&quot;'
</code></pre>
<p>that will actually work and update the <code>value</code> of <code>vip_address</code>?</p>

Jiri Kremser
<p>Of course it can be done with <a href="https://github.com/mikefarah/yq" rel="nofollow noreferrer">mikefarah/yq</a>. You need to drop down to the last level list item <code>env</code> and then use the update-select operator <code>|=</code></p>
<pre class="lang-bash prettyprint-override"><code>yq '.spec.containers[].env |= map(select(.name==&quot;vip_address&quot;).value=&quot;sdf&quot;)' yaml
</code></pre>
<p>Also note that since 4.18.1, <a href="https://mikefarah.gitbook.io/yq/#notice-for-v4.x-versions-prior-to-4.18.1" rel="nofollow noreferrer">yq's <code>eval/e</code></a> command is the default command and no longer needs to be specified.</p>
<hr />
<p>If you want to double-quote the <code>.value</code> field, update the <a href="https://mikefarah.gitbook.io/yq/operators/style#update-and-set-style-of-a-particular-node-using-path-variables" rel="nofollow noreferrer">style</a> for the particular node to double i.e.</p>
<pre class="lang-bash prettyprint-override"><code>yq '.spec.containers[].env |= map(select(.name==&quot;vip_address&quot;).value=&quot;sdf&quot; | .value style=&quot;double&quot;)' yaml
</code></pre>
