Skip to content

Filter the path based in search #1374

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

You must be logged in to vote

Had to think about this one - and I realised that to do it - you need a setpath operator like jq - which yq doesn't yet have. I will add it to the next release, then you will be able to:

yq '(.. | select(tag == "!!str" and test("ghcr.io/junaid18183"))) as $i ireduce({}; setpath($i | path; $i | sub("ghcr.io", "docker.io"))) file.yaml

Explanation:

  1. Find all the entries you wish to update (.. | select(tag == "!!str" and test("ghcr.io/junaid18183"))
  2. Use reduce to create a new object, which will only contain these entries
  3. Create entries in the new object, using the paths of the found entries setpath($i | path ; ...
  4. For the value param of setpath, substitute the old value with the new value

Yo…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@junaid18183
Comment options

@mikefarah
Comment options

@junaid18183
Comment options

Answer selected by junaid18183
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 #1371 on October 05, 2022 08:41.