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

Distinguish my and local?

520


How to know whether a key exists or not in perl?

540


What are perl strings?

516


What are the reasons that cookie server can’t handle multiple connections?

537


What does read () command do?

521






Which statement has an initialization, condition check and increment expressions in its body? Write a syntax to use that statement.

547


What is the use of now constructor in perl?

527


In CPAN module, name an instance you use.

544


Explain ivalue?

546


Write syntax to use grep function?

550


Why we use CGI?

2117


There is no strict data types in perl unlike in other high level languages like Java so wouldn't that be a problem if a code in perl is to be a written by a big team of 20+ members ?"

1998


What happens in dereferencing?

538


What does cgi program store?

541


Write a program to decode the data in the form using cgi programming

547