Unix/Linux Go Back    


How to Post in the The UNIX and Linux Forums Tutorials for how to post and interact in the forums.

Read a json file passed as cmd line argument

How to Post in the The UNIX and Linux Forums


Tags
json, linux, shell script

Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 06-26-2017   -   Original Discussion by RGRT
RGRT's Unix or Linux Image
RGRT RGRT is offline
Registered User
 
Join Date: Jun 2017
Last Activity: 29 June 2017, 2:25 PM EDT
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Read a json file passed as cmd line argument

usage: myscript.sh config.json

config.json:



Code:
{
   "HOST":"abc",
   "DB_NM":"xyz",
   "USR_NM":"asd",
   "PWD":"xxx",
    .........
    .........
    .........
    ........
}

myscript.sh:


Code:

    #HOW TO SOURCE THE config.json file? 
    I would like to use the variables in config.josn file to prepare a query and execute in Linux Shell as show below. 

    host=$HOST/$DB_NM
    usr_nm="--username $USR_NM"
    pwd="--password $PWD"

    query= "--connect $host $usr_nm $pwd"
    eval $query

I am new to shell scripting. Please help me on this.

Last edited by RGRT; 06-29-2017 at 02:22 PM.. Reason: Update
Sponsored Links
    #2  
Old Unix and Linux 06-26-2017   -   Original Discussion by RGRT
vgersh99's Unix or Linux Image
vgersh99 vgersh99 is offline Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 21 April 2018, 5:51 PM EDT
Location: Foxborough, MA
Posts: 8,256
Thanks: 241
Thanked 813 Times in 759 Posts
see if that helps:


Code:
awk -F '("|:)' 'NF>1 {print $2,$5}' config.json

Sponsored Links
    #3  
Old Unix and Linux 06-27-2017   -   Original Discussion by RGRT
RudiC's Unix or Linux Image
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 21 April 2018, 1:54 PM EDT
Location: Aachen, Germany
Posts: 12,504
Thanks: 401
Thanked 3,877 Times in 3,564 Posts
I'm afraid there quite some open questions, like
- which combinations from that config file entries do you need,all permutations from the 10 - 15 entries?
- which section of the file should be used, or is there just one?
- how are you going to use the results, source them in myscript.sh?
- are you sure the host part and the DB part will be joined by a / ?
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Perl Code to change file delimiter (passed as argument) to bar delimiter JPB1977 Shell Programming and Scripting 2 01-05-2014 09:23 AM
Variable passed as argument anil510 Shell Programming and Scripting 3 03-03-2013 04:02 AM
shell script for ftp files passed in command line argument rateeshkumar Shell Programming and Scripting 5 03-23-2011 10:27 PM
File not recognized when passed as argument michaelrozar17 Shell Programming and Scripting 9 08-14-2010 02:17 AM
how to print all argument passed RahulJoshi Shell Programming and Scripting 2 10-13-2008 05:38 PM



All times are GMT -4. The time now is 07:24 PM.