Solved

Linux script for searching logs

Posted on 2014-03-04
3
262 Views
Last Modified: 2014-03-04
I have 31 log files in a directory.  I want to search each log file for a specific string.  It would be nice to search all 30 with a single command.  For output I would just like a count of the matches.  How can I accomplish this?

Directory name: /logs
Log file naming convention:
system.log  -  (today's log)
system.log.* -  (previous 30 day's logs where * is the number 1-30)
0
Comment
Question by:southpau1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 500 total points
ID: 39903617
cd /logs
grep -c "specific string" system.log*

gives a count of matches per file.
0
 
LVL 31

Expert Comment

by:farzanj
ID: 39903619
Try
grep "STRING" system.log*

Open in new window


Use -c option to count matches
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 39903637
To get only a total count of matches (a single number):

grep -hc "specific string" system.log* | awk '{s+=$1} END {print s}'
0

Featured Post

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question