Reputation:
the command below will give the volumes of my Amazon instance
aws ec2 describe-instances --region us-west-2 --instance i-cbd35513 | grep -e "VolumeId" | cut -d ":" -f 2
and the output of that command is:
"vol-f6be8636",
"vol-69be86a9",
But, I want the output
vol-f6be8636
vol-69be86a9
Can anyone please show me or give me an example of how to do it? I would really appreciate of your helps.
Upvotes: 1
Views: 1340
Reputation: 785481
You can do this:
aws ec2 describe-instances --region us-west-2 --instance i-cbd35513 |
awk '/VolumeId/{gsub(/[",]+/, "", $2); print $2}'
There is no need to have grep
and cut
now since my suggested awk command will do all the 3 jobs.
Upvotes: 1
Reputation: 13586
One of the simplest ways is to use tr
:
other-commands | tr -d '",'
Meaning, tr
, delete, then the characters to delete, inside single
quotes so the shell doesn't interpret them.
Upvotes: 0