I have an XML file of the format:
<classes>
<subject lb="Fall Sem 2020">
<name>Operating System</name>
<credit>3</credit>
<type>Theory</type>
<faculty>Prof. XYZ</faculty>
</subject>
<subject lb="Spring Sem 2020">
<name>Web Development</name>
<credit>3</credit>
<type>Lab</type>
</subject>
<subject lb="Fall Sem 2021">
<name>Computer Network</name>
<credit>3</credit>
<type>Theory</type>
<faculty>Prof. ABC</faculty>
</subject>
<subject lb="Spring Sem 2021">
<name>Software Engineering</name>
<credit>3</credit>
<type>Lab</type>
</subject>
</classes>
I'm able to get the desired result using sed
command. i.e. sed -En 's/.* lb="([^"]+)".*/\1/p' file
Output:
Fall Sem 2020
Spring Sem 2020
Fall Sem 2021
Spring Sem 2021
I want this output to be stored in an array. i.e.
arr[0]="Fall Sem 2020"
My try:
arr=($(sed -En 's/.* lb="([^"]+)".*/\1/p' file))
But in this case, I'm getting individual element as an array element. i.e.
arr[0]="Fall"