Assuming that the XML file is well formed:
xmlfile='ES - Physical Inventory Adjustment Report US PDF_es_ES.xlf'
LOBCODE=$( xml sel -t -v '//prop[@prop-type="TemplateCode"]' "$xmlfile" )
This uses XMLStarlet to extract the value of the
prop node whose
prop-type attribute is
TemplateCode. The variable
LOBCODE will get the value
XXPO_PHYS_INV_ADJ_ES_AS with the above XML.
XMLStarlet may sometimes be installed as
xmlstarlet rather than as
There are two issues with your code:
You redirect the output of the
sed command to a file whose name is given by
$LOBCODE is empty, then this redirection will fail. What I assume you wanted to do was to assign the output of
sed to the variable
LOBCODE. This is done with a command substitution as I've shown above. Note that
sed is a poor choice of tool for parsing XML data.
sed to work with a file called
filename. To have
sed work on the value of the variable
filename you will need to use
$ in front of the variable name. Also, since the filename has spaces in it, you need to double quote the variable expansion (you should always do this, regardless). Hence you should use
"$filename" (I've used a more descriptive variable name in my code above).