Replace contents of map containing a multiline string #2684
Replies: 2 comments
|
To be clear |
|
The problem is select(.name == "item2") — your list items don't have a name key, item2 is the map key. So that select matches nothing and the assignment has nothing to write to. Use has() instead: bash Also worth checking your heredoc — cat > << EOF isn't doing what you think. And one gotcha on the block style: yq picks | vs |- based on whether the string ends in a newline, and $(cat <<EOF ...) strips it, so you'd end up with |-. Either keep the trailing newline like above, or force it with ... | (.spec.templates[] | select(has("item2")).item2.stuff) style="literal". Tested on 4.53.3. |
Uh oh!
There was an error while loading. Please reload this page.
Hi
I have the source YAML
I have defined this variable in bash
I have written this expression that seems to do what I want, I.E it selects the correct key and prints the contents
This outputs:-
So I tried
But the item remains unchanged.
I have been through many iterations of this, and this is the first where the source file remains intact. Other options have overwritten the source file with either the contents of item2 or only the contents of item2.stuff. Even when over written i cannot seem to update the contents of
with the contents of
$outputWhat am I doing wrong?
Grateful for any help offered :-)
All reactions