0

I am using below command to list the UserPool Names.

aws cognito-idp list-user-pools --max-results 60 --region us-west-2 --query 'UserPools[*].{Names:Name}'

Now my all UserPool Names contains cust_ as prefix. And i want to remove that from whole list.

I know i can achieve this using jq. But how?

Any help will be highly appreciated.

Thanks!

Jayesh Dhandha
  • 1,983
  • 28
  • 50

1 Answers1

1

If you output with --output text, it will become a text list.

You could then use standard Linux tools such as piping it through | cut -c6-

This will provide character #6 onwards for each line.

Full command would be something like:

aws cognito-idp list-user-pools --max-results 60 --region us-west-2 --query 'UserPools[*].[{Names:Name}]' --output text | cut -c6-
John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
  • Converting output to text is looks complex for the case of many userpools. It will only give `ci` if my userpool name is `cust_ci`. I want Modified JSON. – Jayesh Dhandha May 18 '18 at 07:52
  • 2
    That was what you requested in your question: _"Now my all UserPool Names contains cust\_ as prefix. And i want to remove that from whole list."_ Perhaps you can edit your question and provide some input & output samples if you want a different answer. – John Rotenstein May 18 '18 at 07:58
  • If i run from command line `aws cognito-idp list-user-pools --max-results 60 --region $region --query 'UserPools[*].{Names:Name}' --output text | cut -c6-` Then it is giving each userpool name in new line. But while running same command from shell script, It gives my names with space saperated. `echo \'aws cognito-idp list-user-pools --max-results 60 --region $region --query 'UserPools[*].{Names:Name}' --output text | cut -c6-\`` Any idea? – Jayesh Dhandha May 18 '18 at 08:11
  • Try `UserPools[*].[{Names:Name}]` as per https://github.com/aws/aws-cli/issues/914 – John Rotenstein May 18 '18 at 08:27
  • Yes, that seems to work. I've seen that before, never knew how to solve it! – John Rotenstein May 18 '18 at 08:31
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/171304/discussion-between-jayesh-dhandha-and-john-rotenstein). – Jayesh Dhandha May 18 '18 at 09:12
  • For the moment i have appended `| tr " " "\n"` in my command. Now it is giving me desired output. :) – Jayesh Dhandha May 18 '18 at 09:18