#!/usr/local/bin/perl # search for a file in all subdirectories # $file_ext = '.report'; # match for ' speech and any digit' # $strings = "Percent Total Error"; # look in current directory # $dir = "/cavs/hse/ies/d001/isip/data/exp/tidigits"; chop($dir); # calling a subroutine to serch the directory # &search_directory($dir); # definition of the subroutine # sub search_directory { local ($dir); local(@lines); local($lines); local($count); local(@lines_in_file); local($lines_in_file); local ($file_name); local($subdir); local($file); $dir = $_[0]; # search this directory # @lines = `cd $dir; ls -l`; foreach $lines(@lines) { # any white space and non white space # $lines =~ /\s+(\S+)$/; $file = $1; # checking for the file extension # if ($file =~ /$file_ext$/) { # assigning the path name with extension for o/p later # $file_name = $dir."/".$file; # Open the file # open(elements, $file_name); # read into an array @lines_in_file = ; # initiate the number of matched patterns to 0 # foreach $strings (@strings) { foreach $lines_in_file (@lines_in_file) { # comparing the pattern required to the pattern available in file # if ($lines_in_file =~ /$strings/\s*=\s(.*)\%/) ) { if ($1 < 1.0) { print " $file_name\n"; } # last; } } } # close the file # close(elements); } } # search sub directories if any @lines = `cd $dir; ls -l`; foreach $lines (@lines) { if($lines =~ /^d/) { $lines =~ /\s+(\S+)$/; $subdir = $dir."/".$1; &search_directory($subdir); } } }