skip to Main Content

I am searching through Azure container and want to filter out blobs ending with certain suffixes. When I use the --query parameter with a JMESPath contains function, it is giving me an error.

When I run the command

az storage blob list 
    --account-name $account_name 
    --account-key $key 
    --num-results $numResults 
    --show-next-marker 
    --container-name $container_name 
    --query [].name

it runs without any error.

When I change the query to

    --query [].name[?contains(@,'R00005006')=='true']

or

    --query [].name[?contains(@,'R00005006')]

I get this error:

syntax error near unexpected token `(‘

2

Answers


  1. You need to put the query in quotes for it to be parsed correctly by the command prompt as well as create a projection for it be properly parsed.

    az storage blob list 
        --account-name $account_name 
        --account-key $key 
        --num-results $numResults 
        --show-next-marker 
        --container-name $container_name 
        --query "[*].name | [?contains(@, 'R00005006') == `true`]"
    

    Take note that true is surrounded with a backtick.

    Login or Signup to reply.
  2. If you are looking for the whole blob object content, then you should have your condition on the array of blob objects:

    [?contains(name, `R00005006`)]
    

    So, in you Azure command:

    az storage blob list 
      --account-name $account_name 
      --account-key $key 
      --num-results $numResults 
      --show-next-marker 
      --container-name $container_name 
      --query '[?contains(name, `R00005006`)]'
    

    If you are just looking for a list of names indeed, you have to stop the list projection created by .name with a pipe expression:

    [].name | [?contains(@, `R00005006`)]
    

    So, in your Azure command:

    az storage blob list 
      --account-name $account_name 
      --account-key $key 
      --num-results $numResults 
      --show-next-marker 
      --container-name $container_name 
      --query '[].name | [?contains(@, `R00005006`)]'
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search