I'm having some troubles finding a way to get all matched values from string. I have XML string stored in a variable. From that variable I extract a string with grep. That works well for one match but since grep returns only first matched value it doesn't work exactly how I want it to.
XML="..."
VALUE=($(grep -oP "<tag>(.*)</tag>" <<<"${XML}" | cut -d ">" -f 2 | cut -d "<" -f 1))
Is there any better/smarter way to tackle this than to find value, replace it in existing XML string so it is not a match anymore and then run that in loop until no matches are found?
Short XML example:
<?xml version="1.0" encoding="UTF-8"?>
<xmlDoc>
  <docName>...</docName>
  <formats>
    <format>
      <name>a:1</name>
    </format>
    <format>
      <name>b:2</name>
    </format>
  </formats>
</xmlDoc>
 
    