hi Nicky,
this perl script might help you out
#!/usr/bin/perl
#
#script to search for required text in files
#
my $word1 ; #search word 1
my $word2 ; #search word 2
my @files ; #list of files to search in
my $types ; #tpyes of files
my $log = "log.txt" ; #log file
print "Please enter search word 1:\n";
$word1 = <STDIN>;
chomp ($word1);
print "Please enter search word 2:\n";
$word2 = <STDIN>;
chomp ($word2);
print "Please enter file type to search in:\n";
$types = <STDIN>;
chomp ($types);
open (OUTFILE, ">>$log")|| die "cannot open $log\n";
#array of files in current directory
@files = <*.*>;
foreach $file (@files) {
open (INPUTFILE, $file) || die "cannot open $file\n";
while ( $line = <INPUTFILE>) {
if ( $line =~ /$word1/){
print "found $word1 in $file\n";
print OUTFILE "found $word1 in $file\n";
}
if ( $line =~ /$word2/){
print "found $word2 in $file\n";
print OUTFILE "found $word2 in $file\n";
}
}
close (INPUTFILE);
}
close (OUTFILE);
exit0;
Dino Conti
----- Original Message -----
From: "Nicky Formosa" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>; "Malta Linux User Group - general list"
<[email protected]>
Sent: Friday, October 08, 2004 9:58 AM
Subject: [LINUX.ORG.MT] Search Script
Hi All
I would like to ask you if you can help me with this:
I need a search script that given certain parameters such as:
1) extension type (multiple)
and
2) search text
i will go through a certain folder and search within the documents
(extension types chosen) for the given search text/(s). The text, such as
'Reports Live', should be searched for both the word 'Reports' and the
word
'Live' seperatly but also together. The result should be a log file with
the
names of the documents found!
Is this possible? What i did is the following:
rm search.log
touch search.log
for i in $1*$2
do
if cat $i | grep -a $3 ; then
echo $i >> search.log
fi
done
Where $1 = the folder searching in
$2 = One extension only!
$3 = Search text with no OR
This works but its not exactly what i want! Are there any Search tools
available or?
Tahnks
Nick
_______________________________________________
MLUG-list mailing list
[email protected]
http://mailserv.megabyte.net/mailman/listinfo/mlug-list