Read a json file passed as cmd line argument

Tags
json, linux, shell script

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 06-26-2017
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 03:22 PM.. Reason: Update
# 2  
Old 06-26-2017
see if that helps:
Code:
awk -F '("|:)' 'NF>1 {print $2,$5}' config.json

# 3  
Old 06-27-2017
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 / ?
Login to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Similar Threads More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Getting number of argument passed to a shell script mukulverma2408 Shell Programming and Scripting 4 09-13-2017 12:54 PM
How to read file line by line and compare subset of 1st line with 2nd? pat_pramod Shell Programming and Scripting 3 11-25-2014 03:41 AM
Need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line... Ferocci Shell Programming and Scripting 8 06-28-2014 06:56 AM
Perl Code to change file delimiter (passed as argument) to bar delimiter JPB1977 Shell Programming and Scripting 2 01-05-2014 10:23 AM
Variable passed as argument anil510 Shell Programming and Scripting 3 03-03-2013 05:02 AM
Shell script that check the argument passed to it and prints error if test condition is not met mukulverma2408 Shell Programming and Scripting 3 07-20-2012 10:50 AM
shell script for ftp files passed in command line argument rateeshkumar Shell Programming and Scripting 5 03-23-2011 11:27 PM
Read env variables from argument file bOngY Shell Programming and Scripting 10 12-24-2010 09:46 AM
sed command works from cmd line to standard output but will not write to file crumplecrap Shell Programming and Scripting 1 09-01-2010 02:22 PM
File not recognized when passed as argument michaelrozar17 Shell Programming and Scripting 9 08-14-2010 03:17 AM
bash: read file line by line (lines have '\0') - not full line has read??? alex_5161 Shell Programming and Scripting 6 04-14-2010 05:58 AM
How to take input from cmd line into file metros Programming 4 02-26-2010 01:30 AM
how to print all argument passed RahulJoshi Shell Programming and Scripting 2 10-13-2008 06:38 PM
Check if argument passed is an integers elchalateco Shell Programming and Scripting 13 11-07-2002 09:23 AM
file feed one line per argument jpprial UNIX for Dummies Questions & Answers 10 10-09-2001 11:22 AM
All times are GMT -4. The time now is 02:14 AM.

Unix & Linux Forums Content Copyright 1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password





Not a Forum Member?
Forgot Password?