Re: Counting specific elements in a XML object



Bob Showalter am Donnerstag, 30. März 2006 23.32:
Chas Owens wrote:
If we are going to pick nits then it should be

grep -c "<employee>" fn

Note that grep -c counts matching *lines*. There is no formal
requirement that these elements appear on separate lines.

Dave,

my first one-liner suffers from the same (also only counts lines)

Here's a slightly more complex Perl one-liner that counts *occurences*

perl -lne '$n++ for /<employee>/g; END {print $n}' somefile.xml

Bob,

thanks, I thought about the -n option, but missed the END block idea to
finally print the sum.

(And again, problems that seem to be trivial are not in many cases...)

Hans
.



Relevant Pages

  • Re: Easy One ....I think....
    ... Dave:) ... Doable, but not particularly easy, as you have the data in 6 separate ... Consider making one table (one sheet) with all this data. ... multiple workbooks, but the principle is the same. ...
    (microsoft.public.excel)
  • Re: Firewire external hardrive trouble
    ... >> He said nothing about a firewall, Dave. ... > Yes, he did in a separate, but nearly identical, message posted at 1 ... It might be easier to think of Firewire as "IEEE ...
    (comp.sys.mac.hardware.misc)
  • Re: Cant get my custom cell format to stick
    ... Dave. ... were MID separately, in separate columns). ... "Dave Peterson" wrote: ... But if you're working with text, then changing the numberformat for the cell ...
    (microsoft.public.excel.misc)
  • Re: Usher pre and power amp for sale
    ... Dave ... by using a separate DC one. ... Which is no more than an advertising gimmick. ... Good quality transformers etc emit little in the way of external fields ...
    (uk.rec.audio)
  • Re: Beginner: Referencing a control on another form
    ... > Hi Dave, ... > As for the question you mentioned, I think Deepak's suggestion on apply a ... > actual data should be maintained in the application in separate place. ... > So this is a general progress of interaction between two forms. ...
    (microsoft.public.dotnet.languages.csharp)