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

如何用sed命令替换JSON文件中connectionId内指定字符串

解决方案

核心逻辑

放弃整行替换的c命令,改用行内精准替换:先筛选出包含connectionId的行,只在这些行内替换目标字符串,不改动行内其他内容。

修正后的sed脚本

script: 'sed -e ''/connectionId/s/Resource1005/Resourcetest/g'' "$(System.DefaultWorkingDirectory)/function-app-actions/templates/copycode.json"'

命令详解

  • /connectionId/:仅对包含connectionId关键字的行执行后续操作,防止误修改其他行
  • s/Resource1005/Resourcetest/g:在匹配到的行内,将所有Resource1005替换为Resourcetest(g代表全局替换,确保一行中多次出现的目标字符串都被替换)
  • 全程未使用整行覆盖的c命令,因此行内其他内容(比如订阅ID、连接路径等)都会完整保留

效果验证

执行后,两个connectionId字段会变为:

"connectionId": "/subscriptions/2b06d50xxxxxedd021/resourceGroups/Resourcetest/providers/Microsoft.Web/connections/azureblob",
"connectionId": "/subscriptions/2b06d502xxxxxc8-5a8939edd021/resourceGroups/Resourcetest/providers/Microsoft.Web/connections/office365",

其余JSON结构和内容完全不变。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.15 05:10:40