This bash script tries to get the string "ami-774b7314" from the output of the following command so that it can be used as input to another command in the same script:
aws ec2 describe-images --region ap-southeast-2 --owners amazon --output text --query 'Images[].{A1name:Name,A2id:ImageId}' --filters Name=is-public,Values=true,Name=name,Values=amzn-ami-*.*.*-amazon-ecs-optimized | sort
amzn-ami-2016.03.i-amazon-ecs-optimized ami-22a49541
amzn-ami-2016.03.j-amazon-ecs-optimized ami-862211e5
amzn-ami-2016.09.a-amazon-ecs-optimized ami-73407d10
amzn-ami-2016.09.b-amazon-ecs-optimized ami-5781be34
amzn-ami-2016.09.c-amazon-ecs-optimized ami-774b7314 <===== this line
and to verify it is in the format ami-and-a-mix-of-alphanumeric else echo "bad string" and exit the script
How can it be done?