So I have a multi-line string that I need to pull multiple items from (1 regex string capturing multiple groups). I need to loop through these results.
Example of what I have so far:
#!/bin/bash
string='
    {
        "id" : 45,
        "name" : "John Doe",
        "address" : "123 Fake Street"
    },
    {
        "id" : 46,
        "name" : "Jane Doe",
        "address" : "234 Somewhere Road"
    }
'
regex='\{[^\}]*id" : ([0-9]*)[^\}]*name" : "([a-zA-Z ]*)"[^\}]*address" : "([a-zA-Z0-9 ]*)"[^\}]*}'
if [[ "$string" =~ $regex ]]; then
echo "${BASH_REMATCH[1]} | ${BASH_REMATCH[2]} | ${BASH_REMATCH[3]}"
fi
This outputs:
45 | John Doe | 123 Fake Street
How can I loop thru all the results, to output:
45 | John Doe | 123 Fake Street
46 | Jane Doe | 234 Somewhere Road
47 | Someone else | 777 Nowhere Dr
... etc
Thank you for your help!
 
    