Search code examples
bashxmlstarlet

How to separate the entries of an output file of a select starlet xml command?


I use the starlet xml to find some artifactIds from a pom.xml and i redirect the output to a temporary file, so i can later to create an array with these entries. The problem is that the entries in the temporary file are like one word and they are not separated and when i create the array then the length is 1 instead of 3 for example. The code i wrote is:

xmlstarlet sel -N x=http://maven.apache.org/POM/4.0.0 -t -m "x:project/x:dependencies/x:dependency[x:groupId = '$GROUP_ID']/x:artifactId" -v . $POM_XML > temporary


ARRAY=(`cat temporary`)

and the results are for example:

my-name-is-jonmy-name-is-georgemy-name-is-nick

but i would like to be like:

my-name-is-jon my-name-is-george my-name-is-nick

How can i set a field separator for the temporary? Because as long as the temporary file has them as one entry, my array will also have length 1.. I need to do it with a bash script.

Thank you in advance!


Solution

  • Put -o " " after -v . (Or -o whatever-separator-string-you-want)