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": "[email protected]",
        "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}'

"[email protected]",

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 "[email protected]",

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'
 [email protected]

I got the desired result, but I would prefer to just use awk, instead of having to pipe awk to sed. Is it possible?

  • 1
    The jq program is designed to manipulate json data.
    – icarus
    Commented Jan 22, 2020 at 2:45
  • ok, that's good to know. I just have to run this in an aws lifecycle hook, which executes a shell script, and to avoid any possible issues during the deploy, I planned to stay away from installing packages e.g. apt-get install jq Commented Jan 22, 2020 at 3:07

2 Answers 2


For a one-liner, you can just remove all commas and quotes first.

awk '/Value/ { gsub(/[",]/,""); print $2}'

A better translation of your awk | sed pipeline would be

awk '/Value/ { gsub(/[",]/,"",$2); print $2}'

to just alter the values in the second field.

  • Note that if the value of e.g. Name contains the string Value, this may return unexpected data.
    – Kusalananda
    Commented Jan 22, 2020 at 16:59
  • @Kusalananda Indeed. Using something like jq to parse the data rather than pattern match is clearly the better solution (like using sh rather than csh). The answer given is to the question as asked. I pointed out in the comments that jq would be a suitable tool, and the OP clarified that he didn't want to install any extra packages.
    – icarus
    Commented Jan 22, 2020 at 17:04

Using jq to parse out the value of the Value key in the top-level Parameter structure:

aws ssm get-parameter --name /mysite/dev/email | jq -r '.Parameter.Value'

This will additionally decode any JSON encoding of the value, so that a value that is stored in JSON as \"The Admin\" <[email protected]> comes back as "The Admin" <[email protected]>.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .