Alrighty, I'm trying to get a perl script going to search through a bunch of files for me and compile it to a single location. I am currently having troubles on just getting the grep to work.
Here is what I currently have:
#!/usr/bin/perl
open (LOG, "errors.txt") or die
("Unable to open error.txt");
@errors=<LOG>;
close(LOG);
$errors2 = grep Error,@errors;
foreach ($errors2)
{
chomp($_);
print "$_";
print "\n";
}
Here is the current output:
$ ./perl.sh
7
$
Here is the contents of errors.txt
$ more errors.txt
Error1
Error2
Error3
Makeshift Error
Makeshift
Pluto
jerror
For some reason it's doing a line count. Which is my next thing I wanted to do with it. I want to line count the results to see to even write them, or just skip over writing that section of my perl script.
I'm not too sure if I'm making much sense right now, but I'm just trying re-relearn perl. More of a brush up.
I've tried:
open (LOG, "errors.txt") or die
("Unable to open error.txt");
@errors=<LOG>;
close(LOG);
$errors2 = `grep Error errors.txt`;
foreach ($errors2)
{
chomp($_);
print "$_";
print "\n";
}
Which works fine as well. Then when I try to line count $errors2, it wants to line count the file Error1, Error2, etc.
But when I try to
$errors2 = `grep Error @errors`;
it tries to grep for the word Error in file Error1,Error2,etc. So that doesn't work either.
Any chance another set of eyes could see what I am doing wrong? Thank you for your time. I greatly appriciate it.