Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to use sed or awk in script to print numbers from line?

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

60389922f81a64ddb5f30ab6fe8a73deb643",

>Solution :

What I would do:

awk -F'"' '/^"sha"/{print $4}' file

But I prefer this grep version:

grep -oP '^"sha":\s+"\K[[:xdigit:]]+' file

warning
If the file is JSON, you need jq with something like:

jq -r '.sha' file.json
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading