Skip directly to content

perl

Counting the number of occurrences of a string in a file

on Fri, 07/18/2014 - 15:32
Let's assume you want to find the number of ocurrences of a string in a big XML file, quickly.
Let the filename be 'properties.xml', the keyword string be '<property>', and the script language be Perl. Then, the following command will print the total number of occurrences: 
 
perl -lnwe '$a+=()=/\Q<property>/g; }{ print $a;'  properties.xml
 
 
Tags: