XML : How can I count leading and trailing blanks in xml with awk?

what is the best way to count leading and trailing spaces in XML value? In particular, if I have this xml:

  <?xml version="1.0" encoding="UTF-8"?>  <dvm name="Filename" xml="http://www.google.it">    <description>AL</description>    <columns>      <column>abcde</column>      <column>fg</column>    </columns>    <rows>      <row>        <cell id="1"> 08 4      </cell>        <cell id="2">AG</cell>      </row>      <row>        <cell id="1">    00 6        </cell>        <cell id="2">   AL   </cell>      </row>      <row>        <cell id="1">0 42 </cell>        <cell id="2">AN  </cell>      </row>     </rows>  </dvm>    

How can I count leading and trailing blanks between ">" and the first occurrence of char/digit and/or between last char/digit and the XML end tag value with awk command? I need to know the sum of leading blanks and sum of trailing blanks and put them in two variables. Thanks in advance.

The output should be:

leading: 8

trailing: 20

No comments:

Post a Comment