Dear All,

I want to search a particular word in some set of files, which are kept in
a directory. In this, I want to display the search result in some other out
file like including the line number with file name, etc. For example, if I
want to search the word "Good Try" in all the files in a directory, then
the output should be stored in some "result.out" file which contains
"File1.txt" contains the searchable word "Good Try" at the line number 20.
In this, I've written the below script, in this upto search level working
fine but don't know, how to keep the result in some other file. Can you
please help me in this regard?

### Scripts start###
#!/usr/bin/perl -w

use strict;
use integer;
use File::Basename;

my $find = "Good Try";

@ARGV = ('.') unless @ARGV;

my ($File, $Dir, $Ext) = fileparse($ARGV[0], qr{\..*});

print "Searching in '$Dir'\n";

opendir(DIR, $Dir) or die "\nCan't opendir $Dir: $!.";

my @files = grep (/\.tex$/i, readdir(DIR));
closedir(DIR);

foreach my $file (@files)
{
      my $c = 0;
      my $myFile = $Dir . "\\". $file;
      open (FILE, "<$myFile") or die $!;
      for (<FILE>)
      {
          if ($_ =~ /$find/i)
            {
              $c = $c + 1;
          }
      }
      print $file . "\n" if ($c > 0);
      close(FILE);
}

exit(0);

###end of script###


I've attached a sample file also with this mail. Your helps are highly
appreciated.

Many Thanks,
MadYuv
We start with the one period version of the model. In the next
section we will  (easily) extend the model to Good Start an arbitrary number of
periods.


The constant R is the spot rate for the period, and we can also interpret
the existence of the bond as the existence of a bank with $R$ as its rate of 
Good
Start interest.
-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/

Reply via email to