Nico wrote:
> I have to search all the files in a directory and its subdirectories
> and their subdirectories for a string.
>
> I can search a directory at a time with fgrep 'string' *.*, but this
> is taking ages to do for every dirictory. Is their a way to grep
> recursively through the directories? I could not find anything like
> that in the manual.
Here is my perl script that does this:
#!/usr/bin/perl
# rgrep - recursive grep
use Getopt::Std;
require "finddepth.pl";
getopts('lih');
$opt_h and usage();
$pat=shift or usage();
$d=shift or usage();
-d $d or die "$d is not a directory\n";
finddepth($d);
sub wanted {
-f $_ or return; # we only want plain files:
-z _ and return; # but no empty files:
-B _ and return; # and no binary files:
open(IN,$_);
while(<IN>) {
($opt_i ? /$pat/i : /$pat/) or next;
$opt_l and do { print "$name\n"; last };
print "$name: $_";
}
}
sub usage { die "Usage: rgrep [-l] [-i] pattern ($pat) directory ($d)\n" }
--
Hartelijke groet, Wybo Dekker
___________________Servalys Analytical Chemistry Services__________________
[EMAIL PROTECTED] | Deilsedijk 60 | tel +31-345-652164
www.hobby.nl/~servalys | 4158 CH Deil, The Netherlands | fax +31-345-652383
-
To get out of this list, please send email to [EMAIL PROTECTED] with
this text in its body: unsubscribe suse-linux-e
Check out the SuSE-FAQ at http://www.suse.com/Support/Doku/FAQ/ and the
archiv at http://www.suse.com/Mailinglists/suse-linux-e/index.html