Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search a string in all files within directory

Status
Not open for further replies.

oh5yw

Technical User
Dec 1, 2008
7
FI
The more I study this Perl more I confused...and get Server error 500.
I tried to search solution from internet but cant find any or if found some did not understand it.

problem is this:

I need a script which search with given string all files within specific directory and and print all those lines where string was found.

Files are html-files.

Output does not need to print filenames, only those lines.

Can you professionals help or point me into right direction..

Kari
in cold Finland
 
Post the code you have written so far, even if it does not work. Please note, student posting is not allowed here.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Here is my code. Not mine, but clipped from net. And it is not working

Code:
#!/usr/bin/perl -w
use CGI::Carp qw(fatalsToBrowser);
use strict;
use warnings;


use CGI qw(:all);


use IO::File;

use constant FILE => '*.*';
use constant FIND => '332';

IO::File->input_record_separator(FIND);

my $fh = IO::File->new(FILE, O_RDONLY)
  or die 'Could not open file ', FILE, ": $!";

$fh->getline;  #fast forward to the first match

#print each occurence in the file
print IO::File->input_record_separator
  while $fh->getline;

$fh->close;

And no, I am not student, just old timer whos brains are not so good as they used to be back 50's :)

Kari
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top