2 # Written By Shamir Biton , 27/08/2001
3 # This script can search for text pattern in text file only
5 use Cwd; # to use internal perl libreary
9 my ($startdir) = &cwd; # $startdir will get the current directory value
11 # This part of code take the list of names from $workdir and place it in @names array
13 chdir($workdir) or die "Unable to enter dir $workdir:$!\n";
14 opendir(DIR,".") or die "Unable to open dir $workdir:$!\n";
15 my @names = readdir(DIR) or die "Unable to read dir $workdir:$!\n";
19 foreach my $name (@names)
21 next if ($name eq ".");
22 next if ($name eq "..");
23 next if ($name eq "lost+found");
27 &ScanDirectory($name);
31 if (-T $name) # only if it is text file
33 # print ("Checking $name..\n");
40 if (/$wordTOfind/i) # key word to search
49 print ("Found in $workdir/$name [$NofTimes Times]\n");
55 chdir($startdir) or die "Unable to change dir $startdir:$!\n";
58 my ($defaultdir) = &cwd;
59 printf("Enter root path: [$defaultdir] ");
67 printf("Wrong Directory name, Please Enter Valid path name:");
72 printf("Enter Text To seach: ");
73 $wordTOfind = <STDIN>;
83 &ScanDirectory($userdir);