i have a folder called 'error' and in that, i have error log
files which are generated by the build,
now i want to findout the string 'error' from each log
file and that error has to be copied into the another file
called 'analysis'.
how do you do this in perl?

Answers were Sorted based on User's Feedback



i have a folder called 'error' and in that, i have error log files which are generated by..

Answer / vipul dalwala

# Correction to my above post

$infile = 'errorlog.txt';
$outfile = 'analysys.txt';

open(INFILE,"$infile") || die "Unable to Open $infile-$!";
open(OUTFILE,">$outfile") || die "Unable to Open $outfile-
$!";

while ( <INFILE> ) {
print OUTFILE $_ if (/error/);
}

close INFILE;
close OUTFILE;

Is This Answer Correct ?    6 Yes 1 No

i have a folder called 'error' and in that, i have error log files which are generated by..

Answer / prabhakaran m

## Go to that Directory
my $file_output = "output";

open(OUTFILEHANDLE,">$file_output") || die "Unable to open
the file : $file_output";

foreach my $input_file (`ls -1`) {
open(INFILEHANDLE,"$input_file") || die "Unable to
open the file : $input_file";
while (<INFILEHANDLE>) {
print OUTFILEHANDLE $_ if (/print header/);
}
}

Is This Answer Correct ?    4 Yes 0 No

i have a folder called 'error' and in that, i have error log files which are generated by..

Answer / jyothsna

grep error ~/error/errorlog.txt >> ~/main/analysis.txt

Is This Answer Correct ?    4 Yes 1 No

i have a folder called 'error' and in that, i have error log files which are generated by..

Answer / prabhath kota

We can do it in a simple way through command line with the
use of grep functionality without writing a program for that.

Suppose your log files(err.log, err_others.log, ......) are
present in "logs" folder.

1) Go to that path first
2) logs]# grep -ir 'error' . > result.txt
(-i for ignore case, -r for recursive search)
3) Observe that, it will grep all the places where ever
'error' is present and keep it in result.txt
4) If you just want the file names alone which contains 'error'
logs]# grep -irl 'error' . > result.txt
(-i for ignore case, -r for recursive search,
-l for listing the files)

Is This Answer Correct ?    1 Yes 0 No

i have a folder called 'error' and in that, i have error log files which are generated by..

Answer / vipul dalwala

$infile = 'errorlog.txt';
$outfile = 'analysys.txt';

open(INFILE,$infile) || die "Unable to Open $infile-$!";
open(OUTFILE,$outfile) || die "Unable to Open $outfile-$!";

while ( <INFILE> ) {
print OUTFILE $_ if (/error/);
}

close INFILE;
close OUTFILE;

Is This Answer Correct ?    2 Yes 2 No

Post New Answer

More CGI Perl Interview Questions

what is the function of Return Value?

0 Answers  


Remove the duplicate data from @array=(“perl”,”php”,”perl”,”asp”)

0 Answers  


I have one question regarding to eval function. I know eval function is use for error checking but I am not able to understand below line. eval \'exec perl -S $0 ${1+\"$@\"}\' if 0; $0 for script name $@ set if error occur

0 Answers  


Which has the highest precedence, List or Terms? Explain?

0 Answers  


What are stdin, stdout and stderr?

0 Answers  






Demonstrate subroutines in perl with a simple example.

0 Answers  


How to get help for perl?

0 Answers  


How to sort arrays in perl?

0 Answers  


Explain the use of 'my' keyword in perl?

0 Answers  


What is perl dbi?

0 Answers  


Difference between Perl and Mod_perl?

2 Answers  


What are perl variables?

0 Answers  


Categories