Extract a ids from text file

Solution 1:

The most straightforward answer is to not try and utilize grep, sed, awk, etc for this - even though they will do it, you will most assuredly end up making assumptions and having to constantly shuffle the code.

You could do it with the built-in json module in python, or a purpose-built CLI tool like jq.

jq example:

% cat ids.txt | jq '.data.id'
"ocid1.database.oc1.cd-south-1.amaaaaaago5rdtya6mmvwjfdpdebz7twdxlfdsdssssssaaaaaaadddddd"
"ocid1.database.oc1.cd-south-1.amaaaaaago5rdtya6mmvwjfdpdezzzzzzzzzzzzzzzzzzzddddddddddddddd"

python example:

% cat ids.txt | python3 -c "import sys, json; print(json.load(sys.stdin)['data']['id'])"
ocid1.database.oc1.cd-south-1.amaaaaaago5rdtya6mmvwjfdpdebz7twdxlfdsdssssssaaaaaaadddddd
ocid1.database.oc1.cd-south-1.amaaaaaago5rdtya6mmvwjfdpdezzzzzzzzzzzzzzzzzzzddddddddddddddd