Skip to content

Inplace array merge causing duplicates instead of replace #953

Answered by mssanjay
mssanjay asked this question in Q&A
Discussion options

You must be logged in to vote

I ended up first deleting all array elements by matching Key name and then using Append array elements. I was able to achieve my objective by writing this in a Bash script.

echo "Deleting $routerFile services from $masterFile "
# delete the services from master
for x in $(yq eval '.services[] | .name' $routerFile)
do
    echo "Deleting service from $masterFile - " + $x
    expr="del(.services[] | select(.name ==\"$x\"))"
    echo $expr
    yq eval "$expr" --inplace master.yaml
    if [ $? == 1 ]
    then
        echoerr "*** Delete from masterFile failed ***"
        exit 1
    fi
done

echo "Adding all services from $routerFile into $masterFile"
# append the services from router
yq eval-…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by mikefarah
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants