file.txt
Syndey
####
#!/usr/bin/perl -w
use strict;
our $path_to_dir='/home/path_to_dir/';
sub search_directory($path_to_dir) {
my($listFiles) = @_;
#Insert / at the end if the / is not specified
$listFiles .= '/' if($listFiles !~ /\/$/);
#print "The directory path is $path\n";
# Loop all the files in directory
for my $checkFile (glob($listFiles.'*')) {
## Check the directory
if( -d $checkFile) {
## If the file is directory, them loop again.
&search_directory($checkFile);
}
my $count=0;
open(IN,"$checkFile") or die "$!";
while(){
if ($_ =~ m/<\/book>/ and /*.*Sydney*.*/) {
$count++;
}
}
if($count >= 1){
print "filename:$checkFile and count : $count\n";
}
}
}
&search_directory($path_to_dir);
####
and also Sydney