Solved

Linux script for searching logs

Posted on 2014-03-04
3
261 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

752 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