regex - bash grep part of a json array -
this question has answer here:
- parsing json unix tools 39 answers
inside bash script i've created function returns following json array:
{ "access_token": "sjdhjdydjsdbhggjhsj78dbdsdbmhd=", "scopes": "repository:delete repository:admin repository:write project:write team:write account:write", "expires_in": 3600, "refresh_token": "skdjkjdjdbnbds", "token_type": "bearer" } now wan't grep access token between "". got sjdhjdydjsdbhggjhsj78dbdsdbmhd=
i've created regex below returns grep: invalid repetition count(s) error.
grep -p '\{\s*"access_token"\s*:\s*(.+?)\s*\"' foobar.txt
since you're dependending on nonstandard, nonportable functionality (in form of grep -p), might switch tool that's built job @ hand (and understands json syntax, it'll work if input has, say, newline between key , value, long it's syntactically valid):
jq -r .access_token <foobar.txt
Comments
Post a Comment