Issue
I have this line
"sha": "60dede389922f81a64ddb5f30ab6fe8a73deb643",
How to use sed or awk to print only 60dede389922f81a64ddb5f30ab6fe8a73deb643 ? I have use
awk '/sha/{print $1, $NF}' | sed 's/[^0-9]\{4\}//g'
But I have got wrong vaule
60389922f81a64ddb5f30ab6fe8a73deb643",
Solution
As far that now we know it's JSON:
xidel -e '($json).object.sha' https://api.github.com/repos/fairbird/Youtube-Opensource-DreamOS/git/refs/heads/master
See xidel
Or using curl
and jq
:
curl -Ls https://api.github.com/repos/fairbird/Youtube-Opensource-DreamOS/git/refs/heads/master |
jq -r '.object.sha'
Output:
e14845ed38a605fb8027e8f392581775c61125af
If it's not JSON
:
What I would do:
awk -F'"' '/^"sha"/{print $4}' file
But I prefer this grep
version:
grep -oP '^"sha":\s+"\K[[:xdigit:]]+' file
Answered By - Gilles Quénot Answer Checked By - Gilberto Lyons (WPSolving Admin)