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

Explain goto label?

682


What is the use of -w, -t and strict in Perl?

734


Explain chomp?

678


What are the various advantages and disadvantages of perl?

628


Explain lists ?

679






how to connect cisco switch uisng perl script

3544


What does the’$_’ symbol mean?

733


What are the different string manipulation operators in perl?

689


How to change a directory in perl?

699


What is the usage of -i and 0s options?

710


explain the various functions/directives in perl that allow you to include/import a module. Also, state the differences between them.

609


Explain subroutine?

657


You want to empty an array. How would you do that?

628


What is the purpose of _package_ literal?

699


What is cpan in perl?

701