Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
when i'm trying to access data from XML file by using following cmd its giving data from all matching tag

What I have tried:

$ path="$(echo "cat /config/SourceFolder/FileSetFolder/Path/text()" | xmllint --nocdata --shell real.xml | sed '1d;$d')"

output= rep ------- zip ------- mnt ------- mnt ------- 952230

I need to store each file type in output in to array. Please do the needful

expected output path=(rep,zip,mnt,mnt,952230) as array
Posted
Updated 5-Apr-18 0:30am
v2

1 solution

You can use a for loop to split the string at white spaces and ignore the "-------" matches:
Bash
#!/bin/bash

data="rep ------- zip ------- mnt ------- mnt ------- 952230"

declare -a arr
count=0
for i in $data; do
    if [ "$i" != "-------" ]; then
        arr[count]=$i
        count=$count+1
    fi
done
# Print the array content
echo ${arr[*]}
Note that I have used $data as variable name because $PATH is a predefined bash variable.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900