for each in $(cat ./test.xml | sed "s/</ </g;s/>/> /g" | tr -d "\n")
do
#echo "INPUT: [$each]"
# Create a plain text string version of each
temp=$(echo $each | tr -d "<>")
# Check if its an attrib or data, or an element name
if [[ $(echo $each | cut -c 1-2) == "</" ]]; then
#its an </end> tag
echo "ELEMENT END: [$temp]"
elif [[ $each == "/>" ]]; then
#its a self contained <end /> tag
echo "ELEMENT END: [$lastElement]"
elif [[ $(echo $each | cut -c 1) == "<" ]]; then
#if it starts with a < and isn't either of the above
#then its a <begin> tag
echo "ELEMENT BEGIN: [$temp]"
lastElement=$temp
else
#its either data or an attribute
attribValue=$(echo $temp | cut -d= -f2 )
attribName=$(echo $temp | cut -d= -f1 )
if [[ $attribValue != $attribName ]]; then
#it must be an attribute on an element
echo "AttribName: $attribName"
echo "AttribVal : $attribValue"
else
#it must be data
echo "Data: $each"
fi
unset attribName
unset attribValue
fi
done
Of course, if you do have tools like xmllint to hand...
To find a port in the server index file —
#!/bin/bash
WASBASE=${2:-"/opt/IBM/WebSphere"}
for each in $(find $WASBASE -name serverindex.xml | grep -iv Templates)
do
xmllint --shell $each <<<"xpath //specialEndpoints[contains(@endPointName,'$1')]/endPoint/@port" | grep "=" | cut -d"=" -f2
done
No comments:
Post a Comment