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 . Thanks in advance |
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.
|
More to the point - show us what efforts you have made yourself; either jq, awk, sed, ... whatever.
|
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 |
Quote:
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 |
Quote:
echo "Backup Clinet name $clientname" configfile is the name of the file |
Quote:
|
Quote:
|
Quote:
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 :( |
believe me, much easier to install jq and use it. Especially because you posted the solution in #6.
Code:
grep -P -o '(?<="backup_config_clientname": ")([^"]*)' |
Quote:
Marking this as SOLVED |
As a quick and dirty workaround
Code:
eval clientname="$(awk -F': *' '/backup_config_clientname/,$0=$2' $configfile)" |
Quote:
Quote:
|
All times are GMT -5. The time now is 02:02 PM. |