#!/usr/local/bin/perl -w # Script that browses recursively all the dirs down the one you call from # Find's all the pattern occurencies you need # Print the name of the file with relative path, lines where is has found # and the lines themselves (@ARGV<1) && (die "Must specify a search string\n"); $pattern=$ARGV[0]; $startdir="."; chop ($root=`pwd`); print "\n\nRoot Dir is $root\n"; $dir=$startdir; &recursive($dir); sub search_dir { local($dir)=@_; opendir (DIR,".") || die ("Can't open "."\n"); @files=readdir DIR; close DIR; chop ($long_dir=`pwd`); $long_dir =~ s($root)([ROOT]); foreach $file (@files){ unless (-d $file){ open (FILE,$file) || die ("Can't open $file\n"); $count=0; $found=0; while($line=) { $count++; if ($line=~ /$pattern/) { ($found) || (print ("\n$long_dir/$file:\n")); $found=1; printf ("[%4d] %s",$count,$line); } } close FILE; } } } sub recursive { local($dir)=@_; #print "Dir=$dir\n"; &search_dir($dir); foreach $dir (<*>) { if (-d $dir) { chdir $dir; &recursive($dir); chdir ".."; } } }