Created
December 16, 2011 15:32
-
-
Save shadowbrain/1486478 to your computer and use it in GitHub Desktop.
parse json key:value with sed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Example: Grab the value for the MYSQL_USER key | |
User=$( sed -n 's/.*"MYSQL_USER": "\(.*\)",/\1/p' /var/lib/credentials.json ) | |
## Example: Grab the value for the MYSQL_PASSWORD key | |
Passwd=$( sed -n 's/.*"MYSQL_PASSWORD": "\(.*\)",/\1/p' /var/lib/credentials.json ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
JSON is stored in variable called -
token_response
{ "Code":"Success", "LastUpdated":"2018-12-27T07:16:31Z", "Type":"fakedTypeValue", "AccessKeyId":"fakedAccessKeyIdValue", "Token":"fakedTokenValue" }
When trying to fetch using -
echo aws_access_key_id is:$(echo $token_response | sed -n 's/^.*"AccessKeyId":"\([^"]*\)",*$/\1/p')
Following is printed on console without the token value (Seems value for AccessKeyId is not parsed) -
aws_access_key_id is:
I wonder what's wrong in my regex above?