regex - bash grep part of a json array -


this question has answer here:

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

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -