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?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to get help for perl?

585


How do I sort a hash by the hash value?

556


Explain goto expr?

491


What is the function of cgiwrap in cgi programming?

492


How will you access an element of a perl array?

516






Why we use CGI?

2115


Comment on the scope of variables in perl.

525


How many types of primary data structures in Perl and what do they mean?

845


How to create a directory in perl?

523


What does file test operators do in perl?

500


What is the tk module?

586


What is the closure in PERL?

568


What are the purpose of close(), getc() and read() functions?

479


“The methods defined in the parent class will always override the methods defined in the base class”. What does this statement means?

530


What are the logical operators used for small scale operations?

543