Re: Counting specific elements in a XML object



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.

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

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