Re: Counting specific elements in a XML object
- From: security.department@xxxxxxxx (Hans Meier)
- Date: Fri, 31 Mar 2006 05:27:15 +0100
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
.
- References:
- RE: Counting specific elements in a XML object
- From: Gavin Bowlby
- Re: Counting specific elements in a XML object
- From: Chas Owens
- Re: Counting specific elements in a XML object
- From: Bob Showalter
- RE: Counting specific elements in a XML object
- Prev by Date: grep file file handle
- Next by Date: Re: grep file file handle
- Previous by thread: Re: Counting specific elements in a XML object
- Next by thread: grep file file handle
- Index(es):
Relevant Pages
|