Parse XML line

Hi

I am having an xml file with lines like these

<d name="T2tt_350_100" title="T2tt_012j_350_100_428p4_pPF_PU" add="1" color="4" ls="1" lw="2" normf="1" xsection="0.070152" EqLumi="94651.6" filenames="/user/alkaloge/files/TopTree/7TeV/T2tt_2j_FSim_428p4pPF_S11_PU_350_100/T2tt_2j_FSim_428p4pPF_S11_PU_350_100.root"/>

<d name="T2tt_500_100" title="T2tt_012j_500_100_428p4_pPF_PU" add="1" color="4" ls="1" lw="2" normf="1" xsection="0.006867" EqLumi="936653.56" filenames="/user/alkaloge/files/TopTree/7TeV/T2tt_2j_FSim_428p4pPF_S11_PU_500_100/T2tt_2j_FSim_428p4pPF_S11_PU_500_100.root"/>

How can I use bash to parse each argument ie EqLumi, name etc ?

Thanks bunch

I am puzzle with your request to use bash to parse text.
You can use either awk or sed?.
For example with sed:

sed -e 's/^.*EqLumi="//' file_with_your_xml | sed -e 's/"\s.*//'
$ cat xmlline.sh
#!/bin/bash

# Remove temp file on exit
trap "rm -f /tmp/$$" EXIT

# Little-known incredibly useful property of xargs:  it handles quotes.
# We can use it to transform x='a' y='b c d' into lines like
#
#       x=a
#       y=b c d
#       ...
#
# Ordinary 'while read' loop can handle that easily, splitting on the first =.
xargs printf '%s\n' < xmldata > /tmp/$$

while IFS="=" read NAME VALUE
do
        END=0
        if [ "${VALUE/\/>/}" != "$VALUE" ]      # Check for /> end-of-token
        then
                END=1
                VALUE="${VALUE/\/>/}"
        fi

        [ "${NAME:0:1}" = "<" ] && NAME="${NAME:1}"     # Remove <

        # Sanity check, don't assign variables when we have no value
        if [ ! -z "$VALUE" ]
        then
                VARS="$VARS $NAME"
                read $NAME <<<"$VALUE" # BASH trick to assign variable name without eval
        fi

        # If we found />, print and clear all variables
        if [ "$END" -gt 0 ]
        then
                echo "Found fields $VARS"
                for X in $VARS
                do
                        printf "$X\t${!X}\n"
                        read $X <<<"" # BASH trick to clear variable name without eval
                done
                echo
                VARS=""
        fi
done < /tmp/$$

exit 0

$ ./xmlline.sh
Found fields  name title add color ls lw normf xsection EqLumi filenames
name    T2tt_350_100
title   T2tt_012j_350_100_428p4_pPF_PU
add     1
color   4
ls      1
lw      2
normf   1
xsection        0.070152
EqLumi  94651.6
filenames       /user/alkaloge/files/TopTree/7TeV/T2tt_2j_FSim_428p4pPF_S11_PU_350_100/T2tt_2j_FSim_428p4pPF_S11_PU_350_100.root

Found fields  name title add color ls lw normf xsection EqLumi filenames
name    T2tt_500_100
title   T2tt_012j_500_100_428p4_pPF_PU
add     1
color   4
ls      1
lw      2
normf   1
xsection        0.006867
EqLumi  936653.56
filenames       /user/alkaloge/files/TopTree/7TeV/T2tt_2j_FSim_428p4pPF_S11_PU_500_100/T2tt_2j_FSim_428p4pPF_S11_PU_500_100.root


$