What a challenge to script that in shell !
Here, i've coded something wich works
Code:
LINE="lbla bla bla jcjfd<text>what i want</text>flh%(j blablabla<text>second occurence</text>juhgfiuhf<text>third occ</text>jkhgq"
I=1
LINE=${LINE#*<text>} # Removes all from the begining up to the first "<text>"
LINE=${LINE%</text>*} # Removes all from the end down to the last "</text>"
while echo $LINE | grep -q "<text>" # more than one field
do TEXT[$I]=${LINE%%</text>*}
LINE=${LINE#*<text>}
(( I ++ ))
done
TEXT[$I]=${LINE%</text>*} # for the last one
{ # To see what we've done
N=$I
for I in $(seq $N)
do echo "TEXT[$I] = ${TEXT[$I]}"
done
}
Look if it works by you. If so it's possible to embed it in the appropriate code to parse your files.