Home > front end >  shell script text processing
shell script text processing

Time:09-06

I am working on a shell script to capture all instances names (only) in an az. I am using aws-cli to fetch the list. When i fire the command via script i get the list which is long, i have shortened for it as this is just example. I receive below response to my query.

[ [ "host_abc" ], [ "host_xyz" ], [ "host_foo" ], [ "host_bar" ] ]

I just want capture the host names only and get rid of all other special characters like those square brackets, commas and double quotes. I want to get output as copied below.

host_abc
host_xyz
host_foo
host_bar

Is there a way to filter such response stored in variable or a file in a shell script? Thank you

CodePudding user response:

If your system has jq, it is really helpful for things like this:

aws-cli <whatever> | jq -r 'flatten | join("\n")'
  • Related