Sample Header Ad - 728x90

replace a value in yaml using yq and sed

2 votes
1 answer
1325 views
I am trying to replace a value for key ipAddress using sed for the below yaml block:
networkInterfaces:
- network:
    id: network-1111   
    ipAddress: 192.168.0.0
The command I tried: sed -i 's/\(.*ipAddress:.*\)/ipAddress: 192.168.0.1/g' filename.yaml This actually replaced the text, but it didn't nest the key under networkInterfaces; instead, it placed it in the main block. Output after SED
networkInterfaces:
  - network:
      id: network-1834
ipAddress: 192.168.0.1
I tried yq yq -i '.networkInterfaces.ipAddress = "192.168.0.0"' filename.yaml ... that resulted in an error: cannot index array with 'ipAddress' (strconv.ParseInt: parsing "ipAddress": invalid syntax) I'm looking to replace the value for ipAddress.
Asked by Purushotham Tumuluri (21 rep)
Apr 10, 2024, 08:04 PM
Last activity: Aug 3, 2024, 11:16 PM