I am trying to get the id value but cannot. I also tried escaping " with \"
text="Id": "d246ad6f48f7"
[[ "${text}" =~ (.*)": "(.*)" ]]
echo ${BASH_REMATCH[2]}
I am trying to get the id value but cannot. I also tried escaping " with \"
text="Id": "d246ad6f48f7"
[[ "${text}" =~ (.*)": "(.*)" ]]
echo ${BASH_REMATCH[2]}
the call text="Id": "d246ad6f48f7" returns an error d246ad6f48f7: command not found. You should call text='"Id": "d246ad6f48f7"' instead. But it is hard to match " in bash regex. I recommend using sed like this:
echo '"Id": "d246ad6f48f7"' | sed -E '{s/"(.*)": "(.*)"/\2/}'
d246ad6f48f7
Explanation for sed:
-E extented Regular Expression\2 second backreference