So I have a JSON file which I grep for certain variables:
cat myfile | grep -E "group_(var1|var2|var3)"
The output comes out like this:
"group_var1": "value1"
"group_var2": "value2"
"group_var3": "value3"
I'd like to interpret this in my bash script such that I would end up with the three variables themselves so that I could manipulate them further.
e.g.
echo "$group_var1 $group_var2 $group_var3"
So far I've tried with read -a
, awk '{ print $1 $2 }'
, but none of that brought me closer to my desired result.
The furthest I got was removing the quotes with the following code, but after that, I'm stuck:
params=`cat myfile | grep -E "group_(var1|var2|var3)"`
params=${params//\"}
echoing params now nets me this:
group_var1:value1,group_var2:value2,group_var3:value3,
But now I'm stuck...
Edit & solution:
I went digging further and I got it working by crudely invoking awk for each variable I wanted.
group_var1=`awk '$1=="group_var1:" { sub(",", "", $2); print $2 }' <<< $params
0 Answers