Retrieve the content of a json file using shell script .Without jq /json
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Retrieve the content of a json file using shell script .Without jq /json
I need to get the read contents of this json file
{
"instance": {
"id": "i-061a20e8c5",
"taglist" : [
{"Key": "acp-ims-backup","Value": "sqldb"} ,
{"Key": "created by","Value": "Historia"}
],
"backup_config_clientname": "CAJ-i-061a20e8c"
}
}
I want the value of "backup_config_clientname"
I can assign it to a variable and print it.
using awk or sed .
And what's wrong with jq that you don't want to use it? I mean grep, sed, awk and friends are best suited for manipulating line-oriented data. They are an exceptionally bad fit for parsing non-line oriented formats like JSON or HTML.
I have tried using jq
Well the problem in redhat is just a yum (yum install jq ) command and for suse I have to hit the internet, which I would like to avoid .
I saw these are the commands
zypper addrepo https://download.opensuse.org/reposi...SUSE:12.3.repo
zypper refresh
zypper install json-c
And what's wrong with jq that you don't want to use it? I mean grep, sed, awk and friends are best suited for manipulating line-oriented data. They are an exceptionally bad fit for parsing non-line oriented formats like JSON or HTML.
I have tried using jq
Well the problem in redhat is just a yum (yum install jq ) command and for suse I have to hit the internet, which I would like to avoid .
I saw these are the commands
zypper addrepo https://download.opensuse.org/reposi...SUSE:12.3.repo
zypper refresh
zypper install json-c
I have tried using jq
Well the problem in redhat is just a yum (yum install jq ) command and for suse I have to hit the internet, which I would like to avoid .
I saw these are the commands
zypper addrepo https://download.opensuse.org/reposi...SUSE:12.3.repo
zypper refresh
zypper install json-c
What version/distro of Linux are you using?? Because the repository you mention is VERY old. And why are you wanting to avoid hitting the Internet to install a package? Why is that an issue? Pretty much all distros use online repositories. Also seems fairly easy (providing your input file is consistent), to just grep for "backup_config_clientname", then use awk/sed to tidy it up.
What version/distro of Linux are you using?? Because the repository you mention is VERY old. And why are you wanting to avoid hitting the Internet to install a package? Why is that an issue? Pretty much all distros use online repositories. Also seems fairly easy (providing your input file is consistent), to just grep for "backup_config_clientname", then use awk/sed to tidy it up.
I am using it for a suse 12 machine. Probably for all Suse machines.
I am not good at awk and sed , that's why posted the question
But this code is wrong on so many levels. You really, REALLY (I cannot stress it enough) should be using jq for this even if that means building it from source.
I am using it for a suse 12 machine. Probably for all Suse machines.
If you mean SLES 12, that's a pay-for distro, and as such, you pay for access to the online repositories; again, why are you not wanting to download and install a package easily? And if you mean openSUSE 12, that is ANCIENT and needs to be updated as soon as possible.
Quote:
I am not good at awk and sed , that's why posted the question
If you never try to do anything, you will always be 'not good' at it; given that there are thousands of easily found examples for awk, grep, and sed you could find with simple search terms (like "find a line in a text file with grep" or "split text with awk"), along with the man pages, you could have made a start at trying to do this on your own. Again, we're happy to help, but don't ask us to do it for you.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.