Skip to content

[question][solved]: how do I add to an array contents from another file #1329

Answered by mikefarah
luntik2012 asked this question in Q&A
Discussion options

You must be logged in to vote

Note: Please raise future how to questions under discussion please :)

yq '._anchors_ += loadstr("cert.txt") | (._anchors_[-1] anchor="_myVar")' data.yaml

Explanation:

  • You need to append to the _anchors_ array: ._anchors_ =+ (blah)
  • Load contents as a string from a file loadstr("cert.txt")
  • Next add the anchor to the new element. We do this by selecting the last element in the array, and assign it an anchor: (._anchors_[-1] anchor="_myVar")

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@luntik2012
Comment options

Answer selected by luntik2012
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
Converted from issue

This discussion was converted from issue #1328 on September 08, 2022 01:25.