in reply to Searching word(s) in multiple file and directories

You could use the grep utility if you are working on Unix platforms.

If you are working under Windows, you could use the find utility.

I have written a simple search.pl script in perl to search a directory tree for files containing a regex pattern. It's only tested under Windows.
use strict; use warnings; use File::Find; use Getopt::Long; use Pod::Usage; use Carp; # Parse command line arguments and assign corresponding variables GetOptions ( 'r|rootdir=s' => \( my $rootdir = "./" ), 'p|pattern=s' => \( my $pattern = undef ), 'i' => \( my $case_sensitive = 0 ), 'v|verbose' => \( my $verbose = 0 ), ); unless ( defined $pattern ) { print <<USAGE Usage: $0 [options] Options: -r|--rootdir [dir] Specify the top directory -p|--pattern [pattern] Specify the pattern to look for (regex) -i Case sensitive search -v|--verbose Print more info USAGE ; exit(0); } $pattern = "(?i)" . $pattern if $case_sensitive; print "looking under $rootdir for { /$pattern/ }\n" if $verbose; find({ wanted => \&filefilter }, $rootdir); sub filefilter { return if /^\.+$/; open FILE, "<$File::Find::name" or carp "could not open file: $File::Find::name"; my $file = do { local $/; <FILE> }; close FILE; print ">> ", $File::Find::name, "\n" if $file =~ /$pattern/; }
And the output -
P:\Perl>perl search.pl -r ./ -p "(Find|Dir)" -i >> ./f1.pl >> ./f15.pl >> ./f2.pl >> ./f48.pl >> ./f6.pl >> ./fun1.pl >> ./Fun2.pl >> ./result.txt >> ./search.pl