-1

I have a XML file as follow

<?xml version="1.0" ?>
<coverage branch-rate="0" branches-covered="0" branches-valid="0" complexity="0" line-rate="0.7606" lines-covered="270" lines-valid="355" timestamp="1595999208833" version="5.2.1">
    <!-- Generated by coverage.py: https://coverage.readthedocs.io -->
    <!-- Based on https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd -->
    <sources>
        <source>/home/lebanon/appt</source>
    </sources>
    <packages>
        <package branch-rate="0" complexity="0" line-rate="1" name="application">
            <classes>
                <class branch-rate="0" complexity="0" filename="application/__init__.py" line-rate="1" name="__init__.py">
                    <methods/>
                    <lines>
                        <line hits="1" number="23"/>
                    </lines>
                </class>
            </classes>
        </package>
</coverage>

I want to retrieve line-rate value inside the tag. How can this be achieved using grep ?

rsev4292340
  • 599
  • 1
  • 4
  • 7

1 Answers1

2

You should not parse xml with grep (although you can), so with xmllint you can do this

xmllint --xpath '/coverage/@line-rate' file.xml
Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134