I am extracting an attribute value from xml file, but I get an error.
I'd like to extract the value for key="qua" in the firstpart element. Here is my script, but below you find the errors:
#!/bin/bash
myfile=$1
myvar=$(echo 'cat //firstpart/step/category/id/info[@key="qua"]/@value' | xmllint --xpath "$myfile" | awk -F'[="]' '!/>/{print $(NF-1)}')
echo "$myvar"
how my xml file looks like:
<?xml version='1.0' encoding='UTF-8'?>
<firstpart>
    <step name="Home">    
        <category name="one">
            <id name="tools">
                <info key="qua" value="1"/>        
            </id>
        </category>
    </step>
    <step name="Contact">    
        <category name="two">
            <id name="tools">
                <info key="qua" value="2"/>        
            </id>
        </category>
    </step>
    ...
</firstpart>
<secondpart>
    <step name="office">    
        <category name="one">
            <id name="tools">
                <info key="qua" value="100"/>        
            </id>
        </category>
    </step>
    <step name="Contact">    
        <category name="two">
            <id name="tools">
                <info key="qua" value="200"/>        
            </id>
        </category>
    </step>
    ...
</secondpart>
the errors I get:
awk: run time error: negative field index $-1
    FILENAME="-" FNR=71 NR=71
./mybash.sh: line 3: $: command not found
./mybash.sh: line 4: $: command not found