# yq v4 tools

### Few operators :

1. Length
    
    We can get the length of an array using this length operator
    
    ```yaml
    apple:
      - test: "eat"
      - test: "cut"
    ```
    
    Then the following command gives us the length
    
    ```bash
    length=$(yq '.apple | length' test.yaml)
    ```
    
2. env
    
    This is used to pass variables while using yq
    
    here are a few examples :
    
    ```bash
     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
