Skip to main content
Added sed answer.
Source Link

pcregrep has a smarter -o option that allows you to request an individual capture group.  So,

echo "$json" | pcregrep -o1 '"access_token":"([^"]*)'

This is basically the same as social’s answer, except it doesn’t require as many processes.


Or, doing the (conceptually) same thing entirely in sed,

echo "$json" | sed -En 's/.*"access_token":"([^"]*).*/\1/p'

This is inspired by Paolo Rovelli’s comment.

pcregrep has a smarter -o option that allows you to request an individual capture group.  So,

echo "$json" | pcregrep -o1 '"access_token":"([^"]*)'

This is basically the same as social’s answer, except it doesn’t require as many processes.

pcregrep has a smarter -o option that allows you to request an individual capture group.  So,

echo "$json" | pcregrep -o1 '"access_token":"([^"]*)'

This is basically the same as social’s answer, except it doesn’t require as many processes.


Or, doing the (conceptually) same thing entirely in sed,

echo "$json" | sed -En 's/.*"access_token":"([^"]*).*/\1/p'

This is inspired by Paolo Rovelli’s comment.

Source Link

pcregrep has a smarter -o option that allows you to request an individual capture group.  So,

echo "$json" | pcregrep -o1 '"access_token":"([^"]*)'

This is basically the same as social’s answer, except it doesn’t require as many processes.