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

In reply to Re: Searching word(s) in multiple file and directories by Roger
in thread Searching word(s) in multiple file and directories by TASdvlper

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.