The aws command returns a json string to stdout inside a bash shell.
$ aws ssm get-parameter --name /mysite/dev/email
{
"Parameter": {
"Name": "/mysite/dev/email",
"Type": "String",
"Value": "admin@example.com",
"Version": 1
}
}
I want to return the value of "Value" without the quotes wrapping it. I used a combination of awk and sed linux programs. Basically, awk searches each line in the input and allows you to return a line that has a matching value. Since awk scans a file line by line, allowing you to split the line into fields and perform action on matched pattern, I did this first:
$ aws ssm get-parameter --name /mysite/dev/email | awk -F: '/Value/ {print $2}'
"admin@example.com",
As you can see, I used : as a delimited via the F flag. I matched the line with the string "Value" and then printed the second part of the delimited string, which is the value "user@example.com",
But the quotes and comma are unwelcomed. So I had to use sed with the -E regex flag to replace the quotes and comma:
$ aws ssm get-parameter --name /mysite/dev/email | awk -F: '/Value/ {print $2}' | sed -E 's/"|",//g'
admin@example.com
I got the desired result, but I would prefer to just use awk, instead of having to pipe awk to sed. Is it possible?