Need assistance with bash function

Hi all!

I need a little help with an imbedded fuction I am trying to write. What I am trying to do is go to a series of hosts and get the contents of an XML file, storing some of the data, along with the name of the host it was gathered from. My intent is to store this in an array for later use in the script, but I am having some issues getting the values I am looking for stored in a variable

Assumptions

PHYSICALS_FILE contains entries for hostnames
hosta
hostb
etc

Inventory.xml contains lots of stuff. I am only concerned about the 5th field on lines matching vmxCfgPath

The problem I am having is when I am trying to store the values from the "cat" line into a variable for later use. I have tried defining this line as a variable, but I think there is either an issue with defining a variable in a for loop, or something is happening when I use the pipe (|).... (see the commented out lines)

The output this gives me thus far is:

hosta
vm_number1
vm_number2
hostb
vm_number1
vm_number2
etc

What I would like to get the output to be is

hosta,vm_number1
hosta,vm_number2
hostb,vm_number1
hostb,vm_number2
etc

any insight you can offer would be greatly appreciated!!

here is my snippit (I am sure there is a better way to get this, but this works for the most part)

#!/bin/bash
PROG=`basename $0`
PHYSICALS_FILE=$1
determine_phys ()   {


exec 3< $PHYSICALS_FILE
until [ $DONE ]; do
   read <&3 LINE
   if [[ $? != 0 ]]; then
      DONE=1
      continue
   fi
echo $LINE
   if [[ $? = 0 ]]; then
     sudo ssh $LINE <<EOF
        echo $LINE
        cat /path/to/file/vminventory.xml | grep vmxCfgPath |awk -F"/" '{print $5}'
        #VM=`cat /path/to/file/vminventory.xml | grep vmxCfgPath |awk -F"/" '{print $5}'`
        #echo $LINE,$VM
	echo "___________________________________________"
        exit
EOF
   fi
done
}

determine_phys

A little bothered that this sat here for 19 hours without a response. I am assuming perhaps I did not give enough details to the issue.

Seems there was an issue with the piping I was using...

for reference; here is the corrected code:

gather_info () {
exec 3< $PHYSICALS_FILE
until [ $DONE ]; do
read <&3 LINE
if [[ $? != 0 ]]; then
DONE=1
continue
fi
exec >> final_report.log 2>&1
if [[ $? = 0 ]]; then
sudo ssh $LINE <<EOF
grep vmxCfgPath /etc/vmware/hostd/vmInventory.xml |cut -d '/' -f 5 >>/tmp/vm_list
cat /tmp/vm_list |sed 's/^/$LINE,/'

    rm /tmp/vm_list
    exit

EOF
fi
done
}