in reply to Re: Re: Searching through text files
in thread Searching through text files
Below is a simple solution with little perl code and relying on standard UNIX tools (find and grep). grep -F is used for fast (fixed string instead of regexp) search. It searches all the files in $DIR and all its subdirectories and obtains the names of those matching $STRING. Note that Perl 5.8.0+ is required (for the safe version of open). If you don't have it you must do the shell escaping yourself.
#!/usr/bin/perl # safe form of IPC open requires perl 5.8.0 use v5.8.0; my $DIR = '/some/directory'; my $STRING = 'hidden!'; open my $fh, '-|', 'find', $DIR, qw/-type f -exec grep -lF/, $STRING, +qw/{} ;/ or die $!; chomp (my @found = <$fh>); # @found now contains the list of files matching the string;
|
|---|