Answer the question
In order to leave comments, you need to log in
How to extract a substring from a string using grep?
There is a line received by curl:
{"jsonrpc":"2.0","result":[{"groupid":"63","name":"1voda","internal":"0","flags":"0"}],"id":1}
Answer the question
In order to leave comments, you need to log in
echo '"{"jsonrpc":"2.0","result":[{"groupid":"63","name":"1voda","internal":"0","flags":"0"}],"id":1}"' | cut -d\" -f11
:
echo '{"jsonrpc":"2.0","result":[{"groupid":"63","name":"1voda","internal":"0","flags":"0"}],"id":1}' | jq -r '.result[0].groupid'
:
For a collection
echo "{"jsonrpc":"2.0","result":[{"groupid":"63","name":"1voda","internal":"0","flags":"0"}],"id":1}" | grep -oP "(?<=groupid:)[0-9]*"
How to get the value of the groupid key from it - i.e. the number 63?
echo $MYSTRING|cut -d\" -f 10
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question