You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用yq交换YAML文件中对象数组内的capacityScaler值?

Swapping capacityScaler Values Between Two Backends in YAML Using yq

To swap the capacityScaler values of the two backends in your YAML file, you can use yq's multi-assignment feature to directly exchange the values in one command. Here's how to do it:

Basic Command (Preview Output)

Run this to see the swapped result without modifying your original file:

yq e '(.backends[0].capacityScaler, .backends[1].capacityScaler) = (.backends[1].capacityScaler, .backends[0].capacityScaler)' https_backend.yaml

This expression works by assigning the second backend's capacityScaler value to the first, and the first's value to the second—all in a single step, no temporary variables needed.

In-Place File Edit

If you want to update the file directly instead of just previewing, add the -i (in-place) flag:

yq -i e '(.backends[0].capacityScaler, .backends[1].capacityScaler) = (.backends[1].capacityScaler, .backends[0].capacityScaler)' https_backend.yaml

Verify the Swap

Confirm the change worked using your original command to list the values:

yq e '.backends[].capacityScaler' https_backend.yaml

You’ll now see the output:

1.0
0.0

Note

This uses mikefarah/yq v4+ syntax (the version that uses yq e for evaluate mode), which matches the command you shared in your question. Older versions of yq use different syntax, but this will work with the setup you’re using.

内容的提问来源于stack exchange,提问作者SimpleNiko

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 10:17:39