How to segregate a section from big file?

Hello,

I need to know all IP range (ip_prefix), associated with us-west-2 region only from this link - https://ip-ranges.amazonaws.com/ip-ranges.json (it can be opened in wordpad for better visibility)
Please suggest, how would I do it. If vi, awk or sed is needed, I have downloaded it on my linux server.

Thanks

With 470 posts in these forums over the last 7 1/2 years, we'd expect that you at least have an idea of how to approach that problem. Would you mind to share this with us?

I am great in scripting and I tried few examples in if and then loop, but failed attempts.
From other blog, I am able to achieve my purpose

curl https://ip-ranges.amazonaws.com/ip-ranges.json | jq '.prefixes[] | select(.region == "us-west-2")' | more

I suppose you are reading the following document :
AWS IP Address Ranges - Amazon Web Services

If we look at the example 5 and 6 in the documentation, it is quite close to your requirement.
You do not need to pipe the json parser output to additional shell commands to parse, it should be able to parse JSON format as you wish.
See if this is what you want..

curl https://ip-ranges.amazonaws.com/ip-ranges.json | jq '.prefixes[] | select (.region=="us-west-2") | .ip_prefix'

This is my first time using the jq tool, the one used is from debian repositories.

jq --version
jq-1.5-1-a5b5cbe

Regards
Peasant.

1 Like

Yes, I did, but I was not able to run that command, even if I have configured AWS cli on my computer.
But curl+jq worked very well. Thanks

I was referring to Example 5 and 6 when using jq tool, lower in the documentation, under Linux header.
Be sure to read the documentation carefully and hit specific section which apply to your environment.

Regards
Peasant.

Yes, I got it now. Somehow I skipped this part earlier. Thanks for pointing it out.

Does that mean your problem is solved?