微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

有没有办法使用 yq 命令更改 URL 中的 ip 地址

如何解决有没有办法使用 yq 命令更改 URL 中的 ip 地址

我正在寻找如何使用 yq 命令从 localhost 更改为 ip 地址。下面是例子

来自:

  api:
    in: http://localhost:1141/test-new-api/rest/apiIntegration
    out: http://localhost:1141/test-new-api/rest/outputIntegration

致:

  api:
    in: http://192.168.0.1:1141/test-new-api/rest/apiIntegration
    out: http://192.168.0.1:1141/test-new-api/rest/outputIntegration

正确的格式

url:
  api:
    in: http://localhost:1141/test-new-api/rest/apiIntegration
    out: http://localhost:1141/test-new-api/rest/outputIntegration
  db:
    in: http://localhost:1121/test-new-api/rest/aggregateTaskQuery
    out: http://localhost:1121/test-new-api/rest/insertQuery
  rule: http://localhost:1131/test-new-api/rest/executeRule
  metrics: http://localhost:1191/test-new-api/rest/addTaskMetrics

解决方法

您可以使用 Substitute / Replace string

mikefarah/yq 功能
yq e '.api[] |= sub("localhost:","192.168.0.1:")'

对于要在多个节点上替换的更新问题,请执行

yq e '.url |= (.api[],.db[],.rule,.metrics) |= sub("localhost:","192.168.0.1:")'

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。