LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-27-2012, 04:28 AM   #1
kimbo8
LQ Newbie
 
Registered: Mar 2012
Posts: 1

Rep: Reputation: Disabled
How to build a script that will search for a specific word in a log file


Hello everybody,

I am a new user and pretty new at Linux.

I am looking for a script that i will enter him a path for LOG file, on this log file he will search for about 50-100 error codes that i will configure in the script.
And in the end it will output me the error codes that were find on the log file

And this script needs to be run on real time when log is updated (Shift+F)

For example:

code=202
code=205
code=300
code=122

script runs log file, ending output:
The code that were found are:
code=202
code=205

meaning, these are the codes that were found.

I hope its clear and understandable i have read a little bit on grap commend and tried to find information without success.

Thanks a lot.

Last edited by kimbo8; 03-27-2012 at 04:59 AM.
 
Old 03-27-2012, 05:17 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
What did you not understand about grep? You can either cycle through a file and grep for each individual line in the log file or if the codes are kept in a single file you can also
use the '-f' option to use the file as what grep needs to search for. Have a look at the man page as it is relatively easy to follow.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash shell script read file word by word part 2 justina Programming 7 01-25-2011 01:19 PM
printing a specific word out of a file. rossk Programming 9 01-23-2011 06:11 PM
[SOLVED] bash shell script read file word by word. justina Programming 15 01-22-2011 10:12 AM
search file contains word prospekrisal Linux - Newbie 5 07-20-2006 09:24 PM
search a file for a word - bash script paul_mat Linux - Software 12 04-16-2006 01:59 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration