Skip to content

delete entire document from multi-document file/input #2102

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

You must be logged in to vote

Not currently on a machine with yq - but you should be able to do it like so

yq 'del(select(.kind == "Namespace"))' data.yaml

Explanation:

  • select(.kind == "Namespace") returns all the top level documents that match
  • wrapping that in del( <exp>) will delete those matches
  • See del for more details
  • You can also use the documentIndex/di as a filter: del(select(di == 0)), see document index for more info :)

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@travisghansen
Comment options

@ccoVeille
Comment options

Comment options

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

Answer selected by travisghansen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants