Let's consider an a.txt file containing the following JSON document :
{ "body": { "session_info": { "session_id": "BAzcWu2nHVXrXrx096PMZOaFslgWrjx1", "email": "admin@site.com" }, "status": { "msg": "success" } }
I'm writing a bash script for which I need to extract the session_id value. I started grep'ing with the following regexes, with no success (nothing is returned) :
#!/bin/bash
regex="session_id\": \"[A-Z0-9a-z]{32}.*"
echo "REGEX=$regex"
echo "----"
content=$(cat a.txt)
echo $content
echo "----"
[[ $content =~ $regex ]]
sessionid="${BASH_REMATCH[1]}"
echo ${sessionid}
What is wrong with this ?