I've bumped myself into an interesting (at least for me) problem. Let's take an xml file:
<a>pair1a</a>
<b>pair1b</b>
<c>randomtext</c>
<a>pair2a</a>
<b>pair2b</b>
...
the <b>
tag goes always after <a>
tag. What I want to get is the contents between <a>
and <b>
saved and associated together. How should I approach this problem in bash so that later I could easily access and manage data? I thought about associative arrays or putting everything in one array and separating a contents from b's with somekind of delimiter (althought this might be tricky). My approach was rather simple as in greping everything out into two arrays and then having them to use single index (btw, I've got used to perl regex and that's what grep is using). Can this be done simplier?
a_Array=$(curl --silent -L $xml | grep -oP '(?<=<a>).*?(?=</a>)')
b_Array=$(curl --silent -L $xml | grep -oP '(?<=<b>).*?(?=</b>)')