-1

I am looking how can i change from localhost to ip address using yq command. Below is the example

from :

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

TO:

  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

Correct format

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
Kalyan
  • 11
  • 1
  • 5

1 Answers1

0

You can use the Substitute / Replace string functionality of mikefarah/yq

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

For the updated question to replace on multiple nodes, do

yq e '.url |= (.api[],.db[],.rule,.metrics) |= sub("localhost:", "192.168.0.1:")'
Inian
  • 80,270
  • 14
  • 142
  • 161