yq v4 tools

SUJAY PUJARISUJAY PUJARI
1 min read

Table of contents

Few operators :

  1. Length

    We can get the length of an array using this length operator

     apple:
       - test: "eat"
       - test: "cut"
    

    Then the following command gives us the length

     length=$(yq '.apple | length' test.yaml)
    
  2. env

    This is used to pass variables while using yq

    here are a few examples :

      capitalOfIndia=$(country="India" yq '.[env(country)].capital' test.yaml)
    
  3. unique, sort

    Unique or/and Sort can be used with the help of pipe operator "|".

  4. |, |=, +, +=

    • |

      Typically used to derive block of yaml

    • |=

      Used to update specific block of yaml

    • +=

      To Add a new entry and modify the parent yaml block as well

      • To just add new entry but not update original
  5. Test

0
Subscribe to my newsletter

Read articles from SUJAY PUJARI directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

SUJAY PUJARI
SUJAY PUJARI