LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-29-2006, 06:37 PM   #1
kinetik
Member
 
Registered: Dec 2005
Location: The most beautiful city in the world.
Distribution: Mostly RedHat. Also Suse, Ubuntu, PHLAK etc.
Posts: 149

Rep: Reputation: 15
Search logfiles for specific words


Hi my fellow *Nix guys and gals!

Need some help again.


I'm trying to run a script that will check various services and put it's findings in a txt file, then search a couple of logfiles for specific words (eg. "ERROR"; "Error"; "error") then add the results into the same txt file. Maybe in format "10 instances of error found in logfile1.txt."

I'm stuck at how to search for specific words.

I know you can do less, then /<whatever you want to search for>, but this won't cut it. I need a command I can run that will automatically search the logfile contents and return a number of matching objects.

Any ideas?
 
Old 03-29-2006, 06:53 PM   #2
Vgui
Member
 
Registered: Apr 2005
Location: Canada
Distribution: Slackware
Posts: 496

Rep: Reputation: 31
grep is your tool for this one.
Code:
grep -i "bla" logfile.log
You can pass it plenty of switches, for example -i means case insensitive. You can even pipe the results through further grep statements:
Code:
grep -i "bla" logfile.log | grep -v "info" | wc -l
Here you are grepping for bla (case insensitive), then removing any results that have "info" in them (that's what the -v switch is for), and finally performing a line count on the result.
That should get you going, but check out the man pages, and good luck!
 
Old 03-29-2006, 07:04 PM   #3
kinetik
Member
 
Registered: Dec 2005
Location: The most beautiful city in the world.
Distribution: Mostly RedHat. Also Suse, Ubuntu, PHLAK etc.
Posts: 149

Original Poster
Rep: Reputation: 15
Vgui, you're a star! Thank you very, very much!


EDIT: Sorry Vgui, just one more question. Is there a way to search for eg. "bla", but only any entries from today's date? The logfiles I'm about to query is updated on a constant basis and adds a date before any new entries. Doing a search for bla in this case will result in a lot of entries, but there may not be any entries for today's date...

Last edited by kinetik; 03-29-2006 at 07:45 PM.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
nice egrep 300 search words in one go? shalomajay LinuxQuestions.org Member Intro 2 03-01-2006 05:31 PM
nice egrep 300 search words in one go? shalomajay Programming 1 03-01-2006 03:21 PM
Help working on a script to search for specific data. oracle11112 Programming 26 05-28-2005 07:00 PM
Search and Replace: Asian Words to English Words ieeestd802 Linux - Software 0 10-27-2004 07:48 PM
how to search files with specific contents ? sachinh Linux - Security 4 07-22-2004 08:00 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:56 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