Needing to extract two variables per line from a JSON file and use each of these 2 variables in separate follow up commands.
My script is so far:
#!/bin/bash
VCTRL_OUT='/tmp/workingfile.json'
old_IFS=$IFS # save the field separator
IFS=$'\n' # new field separator, the end of line
for line in $(cat $VCTRL_OUT)
do
python -c 'import json,sys;obj=json.load($line);print obj["ip_range"]'
done
The second to last line is wrong and need to know how to do this.
The following works:
cat /tmp/workingfile.json | head -n +1 | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["ip_range"]';
But not sure how to do the same in the bash script for loop.
$in$linevariable, so instead of the variable's value, you are passing a"$line"string. You need to use double quotes around thepython -c ...command.bash; see Bash FAQ 001.)