#!/usr/local/bin/perl # search for a file in all subdirectories # $file_ext = '.html'; # match for ' speech and any digit' # @strings = ('speech','and','\d'); # look in current directory # $dir = "/cavs/hse/ies/www/"; chop($dir); # calling a subroutine to serch the directory # &search_directory($dir); # definition of the subroutine # sub search_directory { $dir = $_[0]; # search this directory @lines = `cd $dir; ls -l`; foreach $lines(@lines) { #hecking 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 # $count = 0; foreach $strings (@strings) { foreach $line_in_file (@lines_in_file) { # comparing the pattern required to the pattern available in file # if ($line_in_file =~ /$strings/) { #increment if the Number of strings matched # $count += 1; last; } } # close the file # close(elements); # print if all the required patterns are matched # if ($count == 2) { print "$file_name\n"; } } } # 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); } } } }