I have enclosed the script. I am able to find the files that contain my search string but when I try to count the occurences within the file I get zero always. Any help on this.
#!/usr/bin/perl
my $find = $ARGV[0];
my $replace = $ARGV[1];
my $glob = $ARGV[2]; @filelist = <*$glob>;
The other day this forum assisted me with my complex find statement in Unix with my grep, but I have reached the limit of the command line and therefore started to recode in Perl.
My understanding is that perl is much faster, also.
perl has its own grep function and there is no doubt in my mind this is school work, which is not allowed to be posted here. Here is a big problem in the code you posted:
open (IN, "$filename") || die("Error Reading File: $filename $!");
{
undef $/;
$infile = <IN>; <-- HERE THE FILE IS READ
}
close (IN) || die("Error Closing File: $filename $!");
if ($infile =~ m/$find/gio){
print " Matched: $filename\n";
while (<IN>) {<-- HERE THERE IS NOTHING TO READ
while (m/$find/gio) {
$count++;
}
print $ARGV . "contains " . $search_this . " " . $count . (($count == 1) ? " time\n" : " times\n");
}
}
}
See if you can figure it out. I don't do peoples school work for them.
I also want to be able to include path of any file that contains what I am looking for. in my example I am looking for unixsip within files in all . (directories). Can anyone help.
Look at your opening post, where a moderator edited your post to put in code tags for you. And your latest post, where another moderator edited your post to put in code tags for you. And my original post, where I showed you how to do it!
As I mentioned I am learning on the fly at work with no help from anyone here. No one here knows it. This is a real script I am trying to create. I will no longer ask any help from this site.
Unix and perl are not within my job description but was assigned the task to do anyone.