I'm trying to extract several substrings from one string, i want to save those substrings in an Array, so i thought of using a loop but i'm really new into bash scripting.
The original string is something like:
{
"groups":[
{
"group":"",
"favourites":[
{
"category":"",
"longitude":1.0812308,
"latitude":49.4304904,
"test":"",
"color":0,
"name":"Place Henri Gadeau de Kerville, Centre Ville Rive Gauche"
},
{
"category":"",
"longitude":1.940849,
"latitude":48.57248,
"test":"",
"color":0,
"name":"Rue Charles de Gaulle, Saint-Arnoult-en-Yvelines"
},
{
"category":"",
"longitude":1.9358053,
"latitude":48.570592,
"test":"",
"color":0,
"name":"Rue des Remparts, Saint-Arnoult-en-Yvelines"
},
{
"category":"",
"longitude":1.0856655,
"latitude":49.4291327,
"test":"",
"color":0,
"name":"Rue Marie Duboccage (Saint-Sever), Rouen"
},
{
"category":"",
"longitude":1.0845655,
"latitude":49.4251747,
"test":"",
"color":0,
"name":"Rue Octave Crutel, Rouen"
}
],
"color":0
}
]
}
And the desired output is an Array with the names in url mode from the "name" tag like:
Array[0]=Place%20Henri%20Gadeau%20de%20Kerville%2C%20Centre%20Ville%20Rive%20Gauche;
Array[1]=Rue%20Charles%20de%20Gaulle%2C%20Saint-Arnoult-en-Yvelines;
Array[2]=Rue%20des%20Remparts%2C%20Saint-Arnoult-en-Yvelines;
Array[3]=Rue%20Marie%20Duboccage%20(Saint-Sever)%2C%20Rouen;
Array[4]=Rue%20Octave%20Crutel%2C%20Rouen;
...
in order to save the values of the Array in another file and then using them.
I've tried with grep
grep -o '^\"name\":.*\},$' $var
but I cannot get a good result.