I am trying to extract specific XML attribute values for search pattern <factories.*baseQueueName' from resources.xml .
my scripts works ok,, but to extract 3 values this code does echo $line three times, it could be 'n' times. How can I use awk to extract matching pattern values in-line or efficiently than I am doing.
resources.xml
<factories xmi:type="resources.jms.mqseries:MQQueue" xmi:id="MQQueue_11111" name="Queue1" jndiName="jms/Queue1" description="Queue1" category="TEST" persistence="APPLICATION_DEFINED" priority="APPLICATION_DEFINED" specifiedPriority="0" expiry="APPLICATION_DEFINED" specifie dExpiry="0" baseQueueName="TEST.QUEUE1" baseQueueManagerName="" useNativeEncoding="false" integerEncoding="Normal" decimalEncoding="Normal" floatingPointEncoding="IEEENormal" targetClient="JMS" queueManagerHost="" queueManagerPort="0" serverConnectionChannelName="" userName="" password="{xor}" readAhead="NO"/>
<factories xmi:type="resources.jms.mqseries:MQQueue" xmi:id="MQQueue_22222" name="Queue2" jndiName="jms/Queue2" description ="Queue2" category="TEST" persistence="APPLICATION_DEFINED" priority="APPLICATION_DEFINED" specifiedPriority="0" expiry="APPLICATION_DEFINED" specifiedExpiry="0" baseQueueName="TEST.QUEUE2" baseQueueManagerName="" useNativeEncoding="false" integerEncoding="Normal" decimalEncoding="Normal" floa tingPointEncoding="IEEENormal" targetClient="JMS" queueManagerHost="" queueManagerPort="0" serverConnectionChannelName="" userName="" password="{xor}" readAhead="NO"/>
# .. around 20+ similar lines like above.
grep '<factories.*baseQueueName' resources.xml | while read line; do
QUEUE_JNDI_NAME=$( echo $line | grep -Po 'jndiName=\D\S+\D' | cut -d'"' -f2 )
BASE_QUEUE_NAME=$( echo $line | grep -Po 'baseQueueName=\D\S+\D' | cut -d'"' -f2 )
QUEUE_NAME=$( echo $line | grep -Po 'name=\D\S+\D' | cut -d'"' -f2 )
echo "$QUEUE_JNDI_NAME,$BASE_QUEUE_NAME,$QUEUE_NAME"
done
output:
jms/Queue1,TEST.QUEUE1,Queue1
jms/Queue2,TEST.QUEUE2,Queue2
# .. around 20+ similar output lines like above.