I am parsing XML with regex. It is well known so there is no need to worry about escaping etc and proper XML parsing.
grep is returning multiple lines and I want to store each match to a file.
However, I either get each line in between my tags in my array array=( $list )
or I get the whole output array=( "$list" )
.
How can I loop over each match from grep?
My script currently looks like this:
#!/bin/bash
list=$(cat result.xml|grep -ozP '(?s)<tagname.*?tagname>')
array=( "$list" )
arraySize=${#array[@]}
for ((i = 0; i <= $arraySize; i += 1)); do
match="${array[$i]}"
echo "$match" > "$i".xml
done