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.
sedin this case is because you consumed the leading whitespace as you used.*before the key but then you replaced with string ofip.... If you remove the leading.*it does work as intended.