Chris Zampese wrote:
> Hello everyone,
>
> I have a bunch of folders that I would like to search through for a
> particular string. Any hints on how to do this? I do not know the names
> of all the files, but would like to be able to return the name.
>
> Basically this is so I can search a bunch of files for a word, and be able
> to tell which files the word occurs in.
don't know how fancy you want to go about doing this. here is a little code
that lets you search for a bunch of file for something and then print out
those lines and name of the file that match the stuff you are looking for:
#!/usr/bin/perl -w
use strict;
#--
#-- search.pl <word to search> <a bunch of files to search>
#--
my $target = shift;
while(<>){
print "$ARGV: $_" if(/$target/oi);
}
__END__
the following search for the string 'linux' in all files ending with *.txt
in the current directory:
$search.pl linux *.txt
which might print something like:
foo.txt: I like linux
foo.txt: I hate Windos but enjoy Linux
foo.txt: I use Linux all the time
... etc
hope that at least got you started.
david
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]